Основной сайт хуманэмулятор.рф | Демо | Купить | API | Wiki
DOM / interfaces
get_by_id
get_by_id($id,$exactly=true); - Получить интерфейс по атрибуту idФункция на вход принимает параметры:
После выполнения функции возвращаемое значение будет равно одному из двух :
Пример использования
<?php // Scenario: Get elements by ID from a collection // Description: This example demonstrates how to get a collection of elements and then find specific elements by ID within that collection // Classes used: XHEInterfaces, XHEDiv, XHEBrowser, XHEApplication // Connection string to XHE API $xhe_host = getenv("RPABOT_HOST_URL"); // Path to init.php file if (!isset($path)) { // Path to init.php file for connecting to XHE API $path = "../../../Templates/init.php"; // When connecting 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 . "divs.html"); // Example: Get all div elements and then find specific divs by ID within that collection // Get all div elements on the page $divs = DOM::$div->get_all(); // Check that we have found at least one div if ($divs->count() > 0) { echo "Found " . $divs->count() . " div elements\n"; // Try to find a div with a specific ID (exact match) in div elements $targetId = "example"; $divById = $divs->get_by_id($targetId, true); // Check if the div with the specified ID was found in div elements and exists if ($divById && $divById->is_exist()) { echo "\nFound div with ID '" . $targetId . "':\n"; echo "Div inner text: " . $divById->get_inner_text() . "\n"; echo "Div inner number: " . $divById->inner_number . "\n"; echo "Div name: " . $divById->get_name() . "\n"; } else { echo "\nNo div with ID '" . $targetId . "' found in the collection\n"; } // Try to find a div with a partial ID match in div elements $targetId2 = "test"; $divById2 = $divs->get_by_id($targetId2, false); // Check if the div with the specified ID was found in div elements and exists if ($divById2 && $divById2->is_exist()) { echo "\nFound div with ID '" . $targetId2 . "':\n"; echo "Div inner text: " . $divById2->get_inner_text() . "\n"; echo "Div inner number: " . $divById2->inner_number . "\n"; echo "Full ID: " . $divById2->get_id() . "\n"; } else { echo "\nNo div with ID '" . $targetId2 . "' found in the collection\n"; } // Try to find a div with a non-existent ID (exact match) in div elements $nonExistentId = "nonexistent"; $divByNonExistentId = $divs->get_by_id($nonExistentId, true); // Check if the div with the non-existent ID was found in div elements and exists if ($divByNonExistentId && $divByNonExistentId->is_exist()) { echo "\nUnexpectedly found div with ID '" . $nonExistentId . "'\n"; } else { echo "\nAs expected, no div with ID '" . $nonExistentId . "' found in the collection\n"; } } else { echo "No div elements found on the page\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>interfaces.xxxxxxxxx</font><hr>") # 1 echo("1. Перейдем на полигон : ") echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/image.html"),"<br>") # 2 echo("2. Получить все рисунки : ") imgs=image.get_all() echo(imgs.get_count(),"<br>") # 3 echo("3. Получим размеры картинки с id = pic4 : ") img_id_pic4=imgs.get_by_id("pic4") echo(img_id_pic4.get_width()," x ") echo(img_id_pic4.get_height(),"<br>") # 4 echo("4. Получим размеры картинки с id, содержащей 3 : ") img_id_pic3=imgs.get_by_id("3",false) echo(img_id_pic3.get_width()," x ") echo(img_id_pic3.get_height(),"<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 = Environment.GetEnvironmentVariable("RPABOT_HOST_URL"); InitXHE(); // начало echo("<hr><font color=blue>interfaces.get_by_id</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("rpa-bot.ru/wiki/poligon/image.html")+"<br>"); // 2 шаг echo("2. Получить все рисунки : "); XHEInterfaces imgs=image.get_all(); echo(imgs.get_count()+"<br>"); // 3 шаг echo("3. Получим размеры картинки с id = pic4 : "); XHEInterface img_id_pic4=imgs.get_by_id("pic4"); echo(img_id_pic4.get_width()+" x "+img_id_pic4.get_height()+"<br>"); // 4 шаг echo("4. Получим размеры картинки с id, содержащей 3 : "); XHEInterface img_id_pic3=imgs.get_by_id("3",false); echo(img_id_pic3.get_width()+" x "+img_id_pic3.get_height()+"<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_by_id</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/image.html")+"<br>"); // 2 шаг echo("2. Получить все рисунки : "); imgs=image.get_all(); echo(imgs.get_count()+"<br>"); // 3 шаг echo("3. Получим размеры картинки с id = pic4 : "); img_id_pic4=imgs.get_by_id("pic4"); echo(img_id_pic4.get_width()+" x "+img_id_pic4.get_height()+"<br>"); // 4 шаг echo("4. Получим размеры картинки с id, содержащей 3 : "); img_id_pic3=imgs.get_by_id("3",false); echo(img_id_pic3.get_width()+" x "+img_id_pic3.get_height()+"<br>"); // конец echo("\n"); // Quit app.quit();
=============================================
Interfaces Объекты DOM System Vision Web Window
=============================================
Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.