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

get_attribute

get_attribute($name_atr); - получить значение аттрибута объекта в DOM модели

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

  • $name_attr – имя аттрибута, значение котрого надо получить (string). Весь набор аттрибутов, которые есть у элемента можно узнать в инспекторе элементов.

    После отработки функция возвращает результат своей работы в скрипт :
  • значение аттрибута – значение заданного аттрибута у найденного элемента, тип возвращаемого значения string
  • false – найти такой элемент не удалось (например нет вообще элементов, удовлетворяющих заданным критериям или нет такого фрейма), тип возвращаемого значения boolean

    Пример использования
    <?php
    
    // Scenario: For the current page, find a DOM element and get the value of its attribute
    // Description: For the current page, find a DOM element <a> and get the value of its attribute
    // Classes used: XHEAnchor, XHEInterface, XHEBrowser, XHEApplication
    
    // Connection string to XHE API
    $xhe_host = "localhost:7010";
    
    // Path to init.php file
    if (!isset($path))
    {
        // Path to init.php file for connecting to XHE API
        $path = "../../../Templates/init.php";
        // When connecting the init.php file, all functionality of classes for working with XHE API will be available
        require($path);
    }
    
    // Navigate to the polygon page if the page was not loaded earlier
    WEB::$browser->navigate(TEST_POLYGON_URL . "anchor.html");
    
    // Example 1: Get the DOM element anchor by id with text 'onclick' and get the values of its id attribute
    
    // Get the anchor object by id with text 'onclick', attribute value is not an exact match and get the anchor object as XHEInterface
    $targetAnchor = DOM::$anchor->get_by_attribute('id', 'onclick', false);
    
    // Check that the DOM element is received
    if ($targetAnchor->inner_number != -1) {
        // For the found image object, get the value of its 'id' attribute, as a variable
        $targetImageInterfaceAlt = $targetAnchor->get_attribute('id');
    }
    
    // Stop 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>interface.xxxxxxxxx</font><hr>")
    
    # 1 
    echo("1. Перейдем на полигон : ")
    echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html"),"<br>")
    
    # 2 
    echo("2. Получим атрибут 'href' у элемента с текстом, содержащим onclick : ")
    echo(anchor.get_by_inner_text("onclick",false).get_attribute("href"),"<br>")
    
    # 3 
    echo("3. Получим атрибут 'href' , 'id' , 'name' у элемента с текстом, содержащим onclick : ")
    obj=anchor.get_by_inner_text("onclick",false)
    echo(obj.get_attribute("href")," ")
    echo(obj.get_attribute("id")," ")
    echo(obj.get_attribute("name"),"<br>")
    
    # конец
    echo("<hr><br>")
    
    # Quit
    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>interface.get_attribute</font><hr>");
    							
    			// 1 шаг
    			echo("1. Перейдем на полигон : ");
    			echo(browser.navigate("rpa-bot.ru/wiki/poligon/anchor.html")+"<br>");
    			
    			// 2 шаг
    			echo("2. Получим атрибут 'href' у элемента с текстом, содержащим onclick : ");
    			echo(anchor.get_by_inner_text("onclick",false).get_attribute("href")+"<br>");
    			
    			// 3 шаг
    			echo("2. Получим атрибут 'href' , 'id' , 'name' у элемента с текстом, содержащим onclick : ");
    			XHEInterface obj=anchor.get_by_inner_text("onclick",false);
    			echo(obj.get_attribute("href")+" "+obj.get_attribute("id")+" "+obj.get_attribute("name")+"<br>");
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // IE + Chrom
    
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>interface.get_attribute</font><hr>");
    
    // 1 шаг
    echo("1. Перейдем на полигон : ");
    echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html")+"<br>");
    
    // 2 шаг
    echo("2. Получим атрибут 'href' у элемента с текстом, содержащим onclick : ");
    echo(anchor.get_by_inner_text("onclick",false).get_attribute("href")+"<br>");
    
    // 3 шаг
    echo("3. Получим атрибут 'href' , 'id' , 'name' у элемента с текстом, содержащим onclick : ");
    var obj=anchor.get_by_inner_text("onclick",false);
    echo(obj.get_attribute("href")+" "+obj.get_attribute("id")+" "+obj.get_attribute("name")+"<br>");
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

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