humanemulator.net — справка.
Продукт, демо и покупка — на
хуманэмулятор.рф
|
Демо
|
Купить
|
API
|
лог изменений
get_all_by_query_selector
get_all_by_query_selector($selector,$frame=-1); - получить интерфейсы элементов, используя JS Query Selector. (Доступна с версии 4.10.2)Функция на вход принимает параметры:
С версии 4.6.41 достпуно: можно передавать вложенные фреймы, принцип такой же самый, передается строка с номерами фреймов, разделенных : например при передаче "1:0:5" - будет выбран фрейм с номером 1 в нем под фрейм с номером 0 и в нем подфрейм с номером 5
С версии 7.0.38 достпуно: можно передавать "url=>XXX", тогда будет произведен поиск фрейма, который содержит заданнй src, или передавать "name=>XXX" - тогда будет поиск фрейма, по заданной части имени.
После отработки функция возвращает результат своей работы в скрипт :
Пример использования
<?php // Scenario: For the current page, get all DOM elements using CSS query selector // Description: For the current page, get all DOM elements using CSS query selector (document.querySelectorAll) // Classes used: XHEElement, XHEInterfaces, 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 to 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 all elements by class name using query selector // Get all elements by class name using query selector $elements = DOM::$element->get_all_by_query_selector("div"); // Get the count of elements $count = $elements->get_count(); // Display the count echo "Number of elements with class 'some_class': " . $count . "\n"; // If there are any elements, display information about the first one if ($count > 0) { $firstElement = $elements->get(0); if ($firstElement->inner_number != -1) { echo "First element tag: " . $firstElement->get_tag() . "\n"; echo "First element inner text: " . $firstElement->get_inner_text() . "\n"; } } // Example 2: Get all links using query selector // Get all links using query selector $links = DOM::$element->get_all_by_query_selector("a[href]"); // Get the count of links $linkCount = $links->get_count(); // Display the count echo "\nNumber of links with href attribute: " . $linkCount . "\n"; // If there are any links, display information about the first three for ($k = 0; $k < min(3, $linkCount); $k++) { $link = $links->get($k); if ($link->inner_number != -1) { echo "Link " . ($k + 1) . " href: " . $link->get_href() . "\n"; echo "Link " . ($k + 1) . " text: " . $link->get_inner_text() . "\n"; } } // Example 3: Get all input elements of type text using query selector // Get all input elements of type text using query selector $textInputs = DOM::$element->get_all_by_query_selector("input[type='text']"); // Get the count of text inputs $inputCount = $textInputs->get_count(); // Display the count echo "\nNumber of text input elements: " . $inputCount . "\n"; // If there are any text inputs, display information about the first one if ($inputCount > 0) { $firstInput = $textInputs->get(0); if ($firstInput->inner_number != -1) { echo "First text input name: " . $firstInput->get_name() . "\n"; echo "First text input value: " . $firstInput->get_value() . "\n"; } } // Example 4: Get all elements with complex selector // Get all elements with complex selector $complexElements = DOM::$element->get_all_by_query_selector("div.container > p"); // Get the count of elements $complexCount = $complexElements->get_count(); // Display the count echo "\nNumber of p elements inside div.container: " . $complexCount . "\n"; // 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>element.xxxxxxxxx</font><hr>") # 1 echo("1. Перейдем на полигон : ") browser.set_wait_params(10,1) echo(browser.navigate("http://rpa-bot.ru/wiki/"),"<br>") # 2 echo("2. Получить class у всех с заданным query selector : ") objs=element.get_all_by_query_selector(".menu_lnk") print(objs.get_attribute("class")) # конец 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>element.get_all_by_tag</font><hr>"); // 1 echo("1. Перейдем на полигон : "); browser.set_wait_params(10,1); echo(browser.navigate("http://rpa-bot.ru/wiki/")+"<br>"); // 2 echo("2. Получить class у всех с заданным query selector : "); XHEInterfaces objs=element.get_all_by_query_selector(".menu_lnk"); echo(objs.get_attribute("class")); // конец 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_all_by_query_selector</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html")+"\n"); // 2 шаг echo("2. Вызовем метод get_all_by_query_selector : \n"); var result = element.get_all_by_query_selector("selector", -1); echo(result+"\n"); // конец echo("\n"); // уведомляем среду что скрипт закончил работать app.quit();
=============================================
Element Объекты DOM System Vision Web Window
=============================================
Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.