wait_element_exist_by_attribute_by_form_name
wait_element_exist_by_attribute_by_form_name($attr_name,$attr_value,$exactly,$form_name,$frame=-1); - данная функция используется для ожидания появления элемента страницы, проверяя его по значению заданного аттрибута в форме с заданным именем.Доступна с версии 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 attribute within a specific form by name $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 and forms $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 input element with attribute "name" equal to "username" within form named "Form1" to exist $attributeName1 = "name"; $attributeValue1 = "username"; $exactMatch1 = false; $formName1 = "Form1"; echo("\n\nExample 1: Wait for input element to exist by attribute within form by form name\n"); $elementExists = DOM::$input->wait_element_exist_by_attribute_by_form_name($attributeName1, $attributeValue1, $exactMatch1, $formName1); if ($elementExists) { echo "Example 1: Input element with attribute '$attributeName1' equal to '$attributeValue1' exists in form '$formName1'\n"; // Get the input element to perform additional operations echo("Example 1: Get input element by attribute\n"); $findedElement = DOM::$input->get_by_attribute($attributeName1, $attributeValue1); if ($findedElement->is_exist()) { echo "Example 1: Successfully retrieved input element with attribute '$attributeName1' equal to '$attributeValue1' from form '$formName1'\n"; echo "Example 1: Element tag name: " . $findedElement->get_name() . "\n"; } else { echo "Example 1: Failed to retrieve input element with attribute '$attributeName1' equal to '$attributeValue1' from form '$formName1'\n"; } } else { echo "Example 1: Input element with attribute '$attributeName1' equal to '$attributeValue1' does not exist in form '$formName1'\n"; } // Example 2: Wait for submit button element with exact match parameter in Form1 $attributeName2 = "type"; $attributeValue2 = "submit"; $formName2 = "Form1"; $exactMatch2 = true; echo("\n\nExample 2: Wait for button element to exist by attribute with exact match\n"); $elementExistsExact = DOM::$button->wait_element_exist_by_attribute_by_form_name($attributeName2, $attributeValue2, $exactMatch2, $formName2); if ($elementExistsExact) { echo "Example 2: Button element with exact attribute '$attributeName2' equal to '$attributeValue2' exists in form '$formName2'\n"; } else { echo "Example 2: Button element with exact attribute '$attributeName2' equal to '$attributeValue2' does not exist in form '$formName2'\n"; } // Example 3: Wait for password input element in Form2 $attributeName3 = "name"; $attributeValue3 = "passwd"; $formName3 = "Form2"; $exactMatch3 = false; echo("\n\nExample 3: Wait for password input element to exist by attribute within form by form name\n"); $elementExists3 = DOM::$input->wait_element_exist_by_attribute_by_form_name($attributeName3, $attributeValue3, $exactMatch3, $formName3); if ($elementExists3) { echo "Example 3: Password input element with attribute '$attributeName3' equal to '$attributeValue3' exists in form '$formName3'\n"; // Get the password input element echo("Example 3: Get password input element by attribute\n"); $element3 = DOM::$input->get_by_attribute($attributeName3, $attributeValue3, $exactMatch3); if ($element3->is_exist()) { echo "Example 3: Successfully retrieved password input element with attribute '$attributeName3' equal to '$attributeValue3' from form '$formName3'\n"; echo "Example 3: Element tag name: " . $element3->get_name() . "\n"; } else { echo "Example 3: Failed to retrieve password input element with attribute '$attributeName3' equal to '$attributeValue3' from form '$formName3'\n"; } } else { echo "Example 3: Password input element with attribute '$attributeName3' equal to '$attributeValue3' does not exist in form '$formName3'\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_attribute_by_form_name</font><hr>") # 1 echo("1. Перейдем на полигон : ") echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/button.html"),"<br>") # 2 echo("2. Подождём элемент с именем btn1f в форме с именем form1 : ") button.wait_element_exist_by_attribute_by_form_name("name","btn1f",true,"form1") # 3 echo("3. Кликнем на элементе с именем btn1f в форме с именем form1 : ") echo(button.click_by_attribute_by_form_name("name","btn1f",true,"form1"),"<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_attribute_by_form_name</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("rpa-bot.ru/wiki/poligon/button.html")+"<br>"); // 2 шаг echo("2. Ожидаем элемент с именем btn1f в форме с именем form1 : "); button.wait_element_exist_by_attribute_by_form_name("name","btn1f",1,"form1","-1"); // 3 шаг echo("3. Кликнем на элементе с именем btn1f в форме с именем form1 : "); echo(button.click_by_attribute_by_form_name("name","btn1f",1,"form1")+"<br>"); // конец echo("\n\n"); app.quit(); } }
// подключим функциональные объекты, если еще не подключен xhe_host="127.0.0.1:7010"; echo=require("../../../Templates JS/init.js"); // начало echo("<hr><font color=blue>button.wait_element_exist_by_attribute_by_form_name</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/button.html")+"<br>"); // 2 шаг echo("2. Подождём элемент с именем btn1f в форме с именем form1 : "); button.click_by_attribute_by_form_name("name","btn1f",true,"form1"); // 2 шаг echo("2. Кликнем на элементе с именем btn1f в форме с именем form1 : "); echo(button.wait_element_exist_by_attribute_by_form_name("name","btn1f",true,"form1")+"<br>"); // конец echo("\n"); // Quit app.quit();
=============================================
Общие функции Объекты DOM System Vision Web Window
=============================================
Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.
PS: В тестовом примере приведена работа с конкретным объектом DOM, но данная функция есть во всех DOM объектах, т.е она существует у всех объектов из категории DOM.