Основной сайт хуманэмулятор.рф | Демо | Купить | API | Wiki
DOM / interfaces
get_by_name
get_by_name($name,$exactly=true); - Получить интерфейс по атрибуту nameФункция на вход принимает параметры:
После выполнения функции возвращаемое значение будет равно одному из двух :
Пример использования
<?php // Scenario: Get elements by name from a collection // Description: This example demonstrates how to get a collection of elements and then find specific elements by name within that collection // Classes used: XHEInterfaces, XHEAnchor, 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 . "anchors.html"); // Example: Get all anchor elements and then find specific anchors by name within that collection // Get all anchor elements on the page $anchors = DOM::$anchor->get_all(); // Check that we have found at least one anchor if ($anchors->count() > 0) { echo "Found " . $anchors->count() . " anchor elements\n"; // Try to find an anchor with a specific name in anchor elements (exact match) $targetName = "example"; $anchorByName = $anchors->get_by_name($targetName, true); // Check if the anchor with the specified name was found in anchor elements and exists if ($anchorByName && $anchorByName->is_exist()) { echo "\nFound anchor with name '" . $targetName . "' (exact match):\n"; echo "Anchor href: " . $anchorByName->get_href() . "\n"; echo "Anchor inner text: " . $anchorByName->get_inner_text() . "\n"; echo "Anchor inner number: " . $anchorByName->inner_number . "\n"; } else { echo "\nNo anchor with name '" . $targetName . "' (exact match) found in the collection\n"; } // Try to find an anchor with a partial name match in anchor elements $targetName2 = "test"; $anchorByName2 = $anchors->get_by_name($targetName2, false); // Check if the anchor with the specified name was found in anchor elements and exists if ($anchorByName2 && $anchorByName2->is_exist()) { echo "\nFound anchor with name '" . $targetName2 . "' (partial match):\n"; echo "Anchor href: " . $anchorByName2->get_href() . "\n"; echo "Anchor inner text: " . $anchorByName2->get_inner_text() . "\n"; echo "Anchor inner number: " . $anchorByName2->inner_number . "\n"; } else { echo "\nNo anchor with name '" . $targetName2 . "' (partial match) found in the collection\n"; } // Try to find an anchor with a non-existent name in anchor elements (exact match) $nonExistentName = "nonexistent"; $anchorByNonExistentName = $anchors->get_by_name($nonExistentName, true); // Check if the anchor with the non-existent name was found in anchor elements and exists if ($anchorByNonExistentName && $anchorByNonExistentName->is_exist()) { echo "\nUnexpectedly found anchor with name '" . $nonExistentName . "'\n"; } else { echo "\nAs expected, no anchor with name '" . $nonExistentName . "' found in the collection\n"; } // Display all anchor names in the collection for reference echo "\nAll anchor names in the collection:\n"; for ($k = 0; $k < $anchors->count(); $k++) { $currentAnchor = $anchors->get($k); if ($currentAnchor && $currentAnchor->is_exist()) { $anchorName = $currentAnchor->get_name(); $anchorInnerText = $currentAnchor->get_inner_text(); echo "Anchor #" . ($k + 1) . ": Name = '" . $anchorName . "', Text = '" . $anchorInnerText . "'\n"; } } } else { echo "No anchor 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/anchor.html"),"<br>") # 2 echo("2. Получить все ссылки : ") anchors=anchor.get_all() echo(anchors.get_count(),"<br>") # 3 echo("3. Получим размеры ссылки с name = onmouseover : ") onmouseover_anchor=anchors.get_by_name("onmouseover") echo(onmouseover_anchor.get_width()," x ") echo(onmouseover_anchor.get_height(),"<br>") # 4 echo("4. Получим размеры ссылки с name, содержащей note : ") onmouseover_anchor=anchors.get_by_name("note",false) echo(onmouseover_anchor.get_width()," x ") echo(onmouseover_anchor.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_name</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("rpa-bot.ru/wiki/poligon/anchor.html")+"<br>"); // 2 шаг echo("2. Получить все ссылки : "); XHEInterfaces anchors=anchor.get_all(); echo(anchors.get_count()+"<br>"); // 3 шаг echo("3. Получим размеры ссылки с name = onmouseover : "); XHEInterface onmouseover_anchor=anchors.get_by_name("onmouseover"); echo(onmouseover_anchor.get_width()+" x "+onmouseover_anchor.get_height()+"<br>"); // 4 шаг echo("4. Получим размеры ссылки с name, содержащей note : "); XHEInterface note_anchor=anchors.get_by_name("note",false); echo(note_anchor.get_width()+" x "+note_anchor.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_name</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html")+"<br>"); // 2 шаг echo("2. Получить все ссылки : "); anchors=anchor.get_all(); echo(anchors.get_count()+"<br>"); // 3 шаг echo("3. Получим размеры ссылки с name = onmouseover : "); onmouseover_anchor=anchors.get_by_name("onmouseover"); echo(onmouseover_anchor.get_width()+" x "+onmouseover_anchor.get_height()+"<br>"); // 4 шаг echo("4. Получим размеры ссылки с name, содержащей note : "); onmouseover_anchor=anchors.get_by_name("note",false); echo(onmouseover_anchor.get_width()+" x "+onmouseover_anchor.get_height()+"<br>"); // конец echo("\n"); // Quit app.quit();
=============================================
Interfaces Объекты DOM System Vision Web Window
=============================================
Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.