humanemulator.net — справка.
Продукт, демо и покупка — на
хуманэмулятор.рф
|
Демо
|
Купить
|
API
|
лог изменений
get_by_outer_text
get_by_outer_text($outer_text,$exactly=true,$frame=-1); - данная функция используется для получения DOM интерфейса элемента страницы, находя его по заданному внешнему тексту или его части.Доступна с версии 4.9.40
Функция на вход принимает параметры:
С версии 4.6.41 достпуно: можно передавать вложенные фреймы, принцип такой же самый, передается строка с номерами фреймов, разделенных : например при передаче "1:0:5" - будет выбран фрейм с номером 1 в нем под фрейм с номером 0 и в нем подфрейм с номером 5
С версии 7.0.38 достпуно: можно передавать "url=>XXX", тогда будет произведен поиск фрейма, который содержит заданнй src, или передавать "name=>XXX" - тогда будет поиск фрейма, по заданной части имени.
После отработки функция возвращает результат своей работы в скрипт :
Пример использования
<?php // Scenario: Example of getting an element by its outer text $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 various elements WEB::$browser->navigate(TEST_POLYGON_URL . "anchor.html"); // Example 1: Basic usage - get an element by its outer text $outerText = "`id_mouseover1`"; // Outer text that exists in anchor.html (line 40) // Get the element by its outer text (exact match) $findedElement = DOM::$anchor->get_by_outer_text($outerText, true); // Check if the element exists if ($findedElement->is_exist()) { echo "Element with outer text '$outerText' exists.\n"; // Get element information $tagName = $findedElement->get_tag(); $innerHtml = $findedElement->get_inner_html(); echo "Tag name: $tagName\n"; echo "Inner HTML: '$innerHtml'\n"; } else { echo "Element with outer text '$outerText' does not exist.\n"; } echo "\n"; // Example 2: Get an element by partial outer text match $partialOuterText = "Сайт"; // Partial text that exists in multiple elements // Get the element by partial outer text match $findedElement = DOM::$anchor->get_by_outer_text($partialOuterText, false); // Check if the element exists if ($findedElement->is_exist()) { echo "Element with outer text containing '$partialOuterText' exists.\n"; // Get element information $tagName = $findedElement->get_tag(); $innerHtml = $findedElement->get_inner_html(); echo "Tag name: $tagName\n"; echo "Inner HTML: '$innerHtml'\n"; } else { echo "Element with outer text containing '$partialOuterText' does not exist.\n"; } echo "\n"; // Example 3: Get an element by outer text within a frame // This example gets an element from frame 0 (first iframe on the page) $frameOuterText = "Frame0: onmouseover 1"; // Outer text that exists in frame 0 (line 27) // Get the element by exact outer text match within a frame $findedElement = DOM::$anchor->get_by_outer_text($frameOuterText, true, "0"); // Check if the element exists if ($findedElement->is_exist()) { echo "Element with outer text '$frameOuterText' in frame 0 exists.\n"; // Get element information $tagName = $findedElement->get_tag(); $innerHtml = $findedElement->get_inner_html(); echo "Tag name: $tagName\n"; echo "Inner HTML: '$innerHtml'\n"; } else { echo "Element with outer text '$frameOuterText' in frame 0 does not exist.\n"; } echo "\n"; // 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>common.get_by_outer_text</font><hr>") # 1 echo("1. Перейдем на полигон : ") echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html"),"<br>") # 2 echo("2. Получить х и y у ссылки c \"Автомобильный сайт\" и кликнем по ней : ") obj=anchor.get_by_outer_text("Автомобильный сайт") echo(obj.get_x()," ") echo(obj.get_y()," ") echo(obj.click(),"<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>get_by_inner_text</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("rpa-bot.ru/wiki/poligon/anchor.html")+"<br>"); // 2 шаг echo("2. Получить х и y у ссылки c внешним текстом \"Автомобильный сайт\" и кликнем по ней : "); XHEInterface obj=anchor.get_by_outer_text("Автомобильный сайт"); echo(obj.get_x()+" "+obj.get_y()+" "); echo(obj.click()+"<br>"); // конец echo("\n\n"); app.quit(); } }
// подключим функциональные объекты, если еще не подключен xhe_host="127.0.0.1:7010"; echo=require("../../../Templates JS/init.js"); // начало echo("<hr><font color=blue>anchor.get_by_inner_text</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html")+"<br>"); // 2 шаг echo("2. Получить х и y у ссылки c \"Автомобильный сайт\" и кликнем по ней : "); obj=anchor.get_by_inner_text("Автомобильный сайт"); echo(obj.get_x()+" "+obj.get_y()+" "); echo(obj.click()+"<br>"); // конец echo("\n"); // Quit app.quit();
=============================================
Общие функции Объекты DOM System Vision Web Window
=============================================
Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.
PS: В тестовом примере приведена работа с конкретным объектом DOM, но данная функция есть во всех DOM объектах, т.е она существует у всех объектов из категории DOM.