wait_element_exist_by_id
wait_element_exist_by_id($id,$exactly=true,$frame=-1); - данная функция используется для ожидания появления элемента страницы, проверяя его по заданному id.Доступна с версии 7.0.45
Функция на вход принимает параметры:
С версии 4.6.41 достпуно: можно передавать вложенные фреймы, принцип такой же самый, передается строка с номерами фреймов, разделенных : например при передаче "1:0:5" - будет выбран фрейм с номером 1 в нем под фрейм с номером 0 и в нем подфрейм с номером 5
С версии 7.0.38 достпуно: можно передавать "url=>XXX", тогда будет произведен поиск фрейма, который содержит заданнй src, или передавать "name=>XXX" - тогда будет поиск фрейма, по заданной части имени.
Время ожидания элемента задаётся с помощью переменной $iSecondsWaitElementExistBeforeAction=15; // сколько секунд ждать появления элемента определённой в файле шаблона xweb_human_emulator для каждого языка.
<?php // Scenario: Example of waiting for a DOM element to exist by its id attribute $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 DOM elements $pageUrl = TEST_POLYGON_URL . "form.html"; echo("Navigate to HTML page: $pageUrl\n"); WEB::$browser->navigate($pageUrl); WEB::$browser->wait_js(); // Example 1: Wait for an element with id "frm1" to exist (form element) $elementId = "frm1"; $exactly = false; echo("Example 1: Wait for element with id '$elementId' to exist\n"); $elementExists = DOM::$form->wait_element_exist_by_id($elementId, $exactly); if ($elementExists) { echo("Example 1: Element with id '$elementId' exists on the page\n"); // Get the element to perform additional operations $findedElement = DOM::$form->get_by_id($elementId); if ($findedElement->is_exist()) { echo("Example 1: Successfully retrieved element with id '$elementId'\n"); } else { echo("Example 1: Failed to retrieve element with id '$elementId'\n"); } } else { echo("Example 1: Element with id '$elementId' does not exist on the page\n"); } // Example 2: Wait for an element in frame 0 $divNumber = 0; $frameNumber = 0; echo("Example 2: Check if div $divNumber exists on the page\n"); // Wait for an element with id "frm1" (form element) in frame 0 to exist $formElementId = "frm1"; $exactly = false; echo("Example 2: Wait for element form with id '$formElementId' to exist in frame $frameNumber\n"); $elementInFrameExists = DOM::$form->wait_element_exist_by_id($formElementId, $exactly, $frameNumber); if ($elementInFrameExists) { echo("Example 2: Element with id '$formElementId' exists in frame $frameNumber\n"); // Get the element from frame 0 $elementInFrame = DOM::$form->get_by_id($formElementId, $exactly); if ($elementInFrame->is_exist()) { echo("Example 2: Successfully retrieved element with id '$formElementId' from frame $frameNumber\n"); } else { echo("Example 2: Failed to retrieve element with id '$formElementId' from frame $frameNumber\n"); } } else { echo("Example 2: Element with id '$formElementId' does not exist in frame $frameNumber\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.wait_element_exist_by_id</font><hr>") # 1 echo("1. Перейдем на полигон : ") echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html"),"<br>") # 2 echo("2. Подождём элемент с id равным id_onclick : ") anchor.wait_element_exist_by_id("id_onclick",true) # 3 echo("3. Кликнем на элементе с id равным id_onclick : ") echo(anchor.click_by_id("id_onclick",true),"<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>wait_element_exist_by_id</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("rpa-bot.ru/wiki/poligon/anchor.html")+"<br>"); // 2 шаг echo("2. Кликнем на элементе с id равным id_onclick : "); anchor.wait_element_exist_by_id("id_onclick",1,"-1"); // 3 шаг echo("3. Кликнем на элементе с id равным id_onclick : "); echo(anchor.click_by_id("id_onclick",1)+"<br>"); app.quit(); } }
// подключим функциональные объекты, если еще не подключен xhe_host="127.0.0.1:7010"; echo=require("../../../Templates JS/init.js"); // начало echo("<hr><font color=blue>common.wait_element_exist_by_id</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html")+"<br>"); // 2 шаг echo("2. Кликнем на элементе с id равным id_onclick : "); anchor.wait_element_exist_by_id("id_onclick",true); // 3 шаг echo("3. Кликнем на элементе с id равным id_onclick : "); echo(anchor.click_by_id("id_onclick",true)+"<br>");browser.go_back(); // конец echo("\n"); // Quit app.quit();
=============================================
Общие функции Объекты DOM System Vision Web Window
=============================================
Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.
PS: В тестовом примере приведена работа с конкретным объектом DOM, но данная функция есть во всех DOM объектах, т.е она существует у всех объектов из категории DOM.