humanemulator.net — справка. Продукт, демо и покупка — на хуманэмулятор.рф | Демо | Купить | API | лог изменений

get_by_class

get_by_class($class,$exactly=true,$frame="-1"); - Получить интерфейс DOM элемента, который найти по атрибуту class

Функция на вход принимает параметры:

  • $class – Значение атрибута class для поиска DOM элемента
  • $exactly – Требуется точное соответствие значения атрибута? Да/Нет
  • $frame – Номер фрэйма или строка с номерами фреймов, разделенных двоеточием, если фрэйм вложенный или запрос на поиск фрэйма по атрибуту

    После выполнения функции возвращаемое значение будет равно одному из двух :
  • число (Интерфейс)
  • -1 – ошибка

    Пример использования
    <?php
    // Scenario: Getting a DOM element by its class attribute and interacting with it
    $xhe_host = "localhost:7010";
    if (!isset($path)){
        // Path to the init.php file for connecting to the XHE API
        $path = "../../../Templates/init.php";
        // Including init.php grants access to all classes and functionality for working with the XHE API
        require($path);
    }
    
    // Navigate to a webpage with elements having class attributes
    WEB::$browser->navigate(TEST_POLYGON_URL . "anchor.html");
    WEB::$browser->wait_for();
    
    // Example 1: Get element by exact class match
    echo "\n\nExample 1: Get element by exact class match";
    $elementClass = "container";
    $foundElement = DOM::$div->get_by_class($elementClass);
    if ($foundElement->is_exist()) {
        echo "Element with class '{$elementClass}' found\n";
        echo "Element tag: " . $foundElement->get_tag() . "\n";
        echo "Element inner text: " . $foundElement->get_inner_text() . "\n";
    } else {
        echo "Element with class '{$elementClass}' not found\n";
    }
    
    // Example 2: Get element by partial class match
    echo "\n\nExample 2: Get element by partial class match";
    $partialClass = "inner";
    $foundPartialElement = DOM::$div->get_by_class($partialClass, false);
    if ($foundPartialElement->is_exist()) {
        echo "\nElement with partial class '{$partialClass}' found\n";
        echo "Element tag: " . $foundPartialElement->get_tag() . "\n";
        echo "Element inner text: " . $foundPartialElement->get_inner_text() . "\n";
    } else {
        echo "\nElement with partial class '{$partialClass}' not found\n";
    }
    
    // Example 3: Get element by class within a specific frame (frame=0)
    echo "\n\nExample 3: Get element by class within a specific frame (frame=0)";
    $frameElementClass = "link pageNextPrev {page:6}"; // Actual class that exists in frame
    $foundFrameElement = DOM::$anchor->get_by_class($frameElementClass, true, "0");
    if ($foundFrameElement->is_exist()) {
        echo "\nElement with class '{$frameElementClass}' in frame 0 found\n";
        echo "Element tag: " . $foundFrameElement->get_tag() . "\n";
        echo "Element inner text: " . $foundFrameElement->get_inner_text() . "\n";
    } else {
            echo "\nElement with class '{$frameElementClass}' in frame 0 not found\n";
            echo "Note: Frame 0 contains elements with classes like 'link pageNextPrev {page:6}', etc.";
    }
    
    // Quit the application
    WINDOW::$app->quit();
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7010"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>element.get_by_class</font><hr>")
    
    # 1 шаг
    echo("1. Перейдем на полигон : ");
    echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html"));
    
    # 2 шаг
    echo("2. Вызовем метод get_by_class : ");
    result = element.get_by_class("class", True, "-1")
    echo(result);
    
    # конец
    echo("<hr><br>")
    
    # уведомляем среду что скрипт закончил работать
    app.quit()
    #region using
    
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
    
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
    
    #endregion
    
     class Program:XHEScript
     {
    	  static void Main(string[] args)
    	  {
    			// init XHE
    			server = "localhost:7010";
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>a_common.get_by_class</font><hr>");
    
    			// 1 шаг
    			echo("1. Перейдем на полигон : ");
    			echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html")+"\n\n");
    
    			// 2 шаг
    			echo("2. Вызовем метод get_by_class : ");
    			dynamic result = element.get_by_class("class", true, "-1");
    			echo(result+"\n\n");
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>element.get_by_class</font><hr>");
    
    // 1 шаг
    echo("1. Перейдем на полигон : ");
    echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html")+"\n");
    // 2 шаг
    echo("2. Вызовем метод get_by_class : \n");
    var result = element.get_by_class("class", true, "-1");
    echo(result+"\n");
    
    // конец
    echo("\n");
    
    // уведомляем среду что скрипт закончил работать
    app.quit();

    =============================================
    a_common    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.

    PS: В тестовом примере приведена работа с конкретным объектом DOM, но данная функция есть во всех DOM объектах, т.е она существует у всех объектов из категории DOM.