Основной сайт хуманэмулятор.рф | Демо | Купить | API | Wiki
DOM / interfaces
get_by_outer_text
get_by_outer_text($outer_text,$exactly=true); - Получить интерфейс по внешнему текстуФункция на вход принимает параметры:
После выполнения функции возвращаемое значение будет равно одному из двух :
Пример использования
<?php // Scenario: Get elements by outer text from a collection // Description: This example demonstrates how to get a collection of elements and then find specific elements by their outer text 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 outer text 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 outer text (exact match) in anchor elements $targetText = "Example Link"; $anchorByText = $anchors->get_by_outer_text($targetText, true); // Check if the anchor with the specified outer text was found in anchor elements and exists if ($anchorByText && $anchorByText->is_exist()) { echo "\nFound anchor with outer text '" . $targetText . "' (exact match):\n"; echo "Anchor href: " . $anchorByText->get_href() . "\n"; echo "Anchor inner number: " . $anchorByText->inner_number . "\n"; echo "Anchor inner text: " . $anchorByText->get_inner_text() . "\n"; } else { echo "\nNo anchor with outer text '" . $targetText . "' (exact match) found in the collection\n"; } // Try to find an anchor with a partial outer text match in anchor elements $partialText = "Link"; $anchorByPartialText = $anchors->get_by_outer_text($partialText, false); // Check if the anchor with the partial outer text was found in anchor elements and exists if ($anchorByPartialText && $anchorByPartialText->is_exist()) { echo "\nFound anchor with partial outer text '" . $partialText . "':\n"; echo "Anchor href: " . $anchorByPartialText->get_href() . "\n"; echo "Anchor inner number: " . $anchorByPartialText->inner_number . "\n"; echo "Full outer text: " . $anchorByPartialText->get_outer_text() . "\n"; } else { echo "\nNo anchor with partial outer text '" . $partialText . "' found in the collection\n"; } // Try to find an anchor with another outer text in anchor elements $targetText2 = "Test"; $anchorByText2 = $anchors->get_by_outer_text($targetText2, true); // Check if the anchor with the specified outer text was found in anchor elements and exists if ($anchorByText2 && $anchorByText2->is_exist()) { echo "\nFound anchor with outer text '" . $targetText2 . "':\n"; echo "Anchor href: " . $anchorByText2->get_href() . "\n"; echo "Anchor inner number: " . $anchorByText2->inner_number . "\n"; } else { echo "\nNo anchor with outer text '" . $targetText2 . "' found in the collection\n"; } // Try to find an anchor with a non-existent outer text in anchor elements $nonExistentText = "NonExistentLink"; $anchorByNonExistentText = $anchors->get_by_outer_text($nonExistentText, true); // Check if the anchor with the non-existent outer text was found in anchor elements and exists if ($anchorByNonExistentText && $anchorByNonExistentText->is_exist()) { echo "\nUnexpectedly found anchor with outer text '" . $nonExistentText . "'\n"; } else { echo "\nAs expected, no anchor with outer text '" . $nonExistentText . "' found in the collection\n"; } // Display all anchor outer texts in the collection for reference echo "\nAll anchor outer texts in the collection:\n"; for ($k = 0; $k < $anchors->count(); $k++) { $currentAnchor = $anchors->get($k); if ($currentAnchor && $currentAnchor->is_exist()) { $anchorOuterText = $currentAnchor->get_outer_text(); $anchorInnerText = $currentAnchor->get_inner_text(); $anchorHref = $currentAnchor->get_href(); echo "Anchor #" . ($k + 1) . ": Outer Text = '" . $anchorOuterText . "', Inner Text = '" . $anchorInnerText . "', Href = '" . $anchorHref . "'\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. Получим размеры ссылки с текстом = ссылка onmouseover : ") onmouseover_anchor=anchors.get_by_outer_text("ссылка onmouseover") echo(onmouseover_anchor.get_width()," x ") echo(onmouseover_anchor.get_height(),"<br>") # 4 echo("4. Получим размеры ссылки с текстом, содержащей SEO : ") onmouseover_anchor=anchors.get_by_outer_text("SEO",false) echo(onmouseover_anchor.get_width()," x ") echo(onmouseover_anchor.get_height(),"<br>") # конец echo("<hr><br>") # Quit app.quit()
=============================================
Interfaces Объекты DOM System Vision Web Window
=============================================
Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.