Основной сайт хуманэмулятор.рф | Демо | Купить | API | Wiki
DOM / interfaces
get_by_href
get_by_href($href,$exactly=true); - Получить интерфейс по атрибуту hrefФункция на вход принимает параметры:
После выполнения функции возвращаемое значение будет равно одному из двух :
Пример использования
<?php // Scenario: Get elements by href attribute from a collection // Description: This example demonstrates how to get a collection of elements and then find specific elements by their href attribute 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 their href attribute 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 href (exact match) in anchor elements $targetHref = "http://example.com"; $anchorByHref = $anchors->get_by_href($targetHref, true); // Check if the anchor with the specified href was found in anchor elements and exists if ($anchorByHref && $anchorByHref->is_exist()) { echo "\nFound anchor with href '" . $targetHref . "' (exact match):\n"; echo "Anchor inner text: " . $anchorByHref->get_inner_text() . "\n"; echo "Anchor inner number: " . $anchorByHref->inner_number . "\n"; echo "Anchor name: " . $anchorByHref->get_name() . "\n"; } else { echo "\nNo anchor with href '" . $targetHref . "' (exact match) found in the collection\n"; } // Try to find an anchor with a partial href match in anchor elements and exists $partialHref = "example"; $anchorByPartialHref = $anchors->get_by_href($partialHref, false); // Check if the anchor with the partial href was found in anchor elements if ($anchorByPartialHref && $anchorByPartialHref->is_exist()) { echo "\nFound anchor with partial href '" . $partialHref . "':\n"; echo "Anchor inner text: " . $anchorByPartialHref->get_inner_text() . "\n"; echo "Anchor inner number: " . $anchorByPartialHref->inner_number . "\n"; echo "Full href: " . $anchorByPartialHref->get_href() . "\n"; } else { echo "\nNo anchor with partial href '" . $partialHref . "' found in the collection\n"; } // Try to find an anchor with a non-existent href $nonExistentHref = "http://nonexistent.com"; $anchorByNonExistentHref = $anchors->get_by_href($nonExistentHref, true); // Check if the anchor with the non-existent href was found if ($anchorByNonExistentHref && $anchorByNonExistentHref->is_exist()) { echo "\nUnexpectedly found anchor with href '" . $nonExistentHref . "'\n"; } else { echo "\nAs expected, no anchor with href '" . $nonExistentHref . "' found in the collection\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. Получим размеры ссылки с href = https://rpa-bot.ru/wiki/ : ") qstart_anchor=anchors.get_by_href("https://rpa-bot.ru/wiki/") echo(qstart_anchor.get_width()," x ") echo(qstart_anchor.get_height(),"<br>") # 4 echo("4. Получим размеры ссылки с текстом, содержащей note : ") note_anchor=anchors.get_by_href("note",false) echo(note_anchor.get_width()," x ") echo(note_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_href</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. Получим размеры ссылки с href = https://rpa-bot.ru/wiki/ : "); XHEInterface qstart_anchor=anchors.get_by_href("https://rpa-bot.ru/wiki/"); echo(qstart_anchor.get_width()+" x "+qstart_anchor.get_height()+"<br>"); // 4 шаг echo("4. Получим размеры ссылки с текстом, содержащей note : "); XHEInterface note_anchor=anchors.get_by_href("note",false); echo(note_anchor.get_width()+" x "+note_anchor.get_height()+"<br>"); // конец echo("\n\n"); app.quit(); } }
// подключим функциональные объекты, если еще не подключен xhe_host="127.0.0.1:7010"; echo=require("../../../Templates JS/init.js"); // начало echo("<hr><font color=blue>interface.get_by_href</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. Получим размеры ссылки с href = https://rpa-bot.ru/wiki/ : "); qstart_anchor=anchors.get_by_href("https://rpa-bot.ru/wiki/"); echo(qstart_anchor.get_width()+" x "+qstart_anchor.get_height()+"<br>"); // 4 шаг echo("4. Получим размеры ссылки с текстом, содержащей note : "); note_anchor=anchors.get_by_href("note",false); echo(note_anchor.get_width()+" x "+note_anchor.get_height()+"<br>"); // конец echo("\n"); // Quit app.quit();
=============================================
Interfaces Объекты DOM System Vision Web Window
=============================================
Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.