humanemulator.net — справка.
Продукт, демо и покупка — на
хуманэмулятор.рф
|
Демо
|
Купить
|
API
|
Changelog
get_by_src
get_by_src($src,$exactly=true); - Получить интерфейс по атрибуту srcФункция на вход принимает параметры:
После выполнения функции возвращаемое значение будет равно одному из двух :
Пример использования
<?php // Scenario: Get elements by src attribute from a collection // Description: This example demonstrates how to get a collection of elements and then find specific elements by their src attribute within that collection // Classes used: XHEInterfaces, XHEImage, 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 . "images.html"); // Example: Get all image elements and then find specific images by their src attribute within that collection // Get all image elements on the page $images = DOM::$image->get_all(); // Check that we have found at least one image if ($images->count() > 0) { echo "Found " . $images->count() . " image elements\n"; // Try to find an image with a specific src (exact match) in image elements $targetSrc = "example.jpg"; $imageBySrc = $images->get_by_src($targetSrc, true); // Check if the image with the specified src was found in image elements and exists if ($imageBySrc && $imageBySrc->is_exist()) { echo "\nFound image with src '" . $targetSrc . "' (exact match):\n"; echo "Image alt: " . $imageBySrc->get_alt() . "\n"; echo "Image inner number: " . $imageBySrc->inner_number . "\n"; echo "Image width: " . $imageBySrc->get_width() . "\n"; echo "Image height: " . $imageBySrc->get_height() . "\n"; } else { echo "\nNo image with src '" . $targetSrc . "' (exact match) found in the collection\n"; } // Try to find an image with a partial src match in image elements $partialSrc = "example"; $imageByPartialSrc = $images->get_by_src($partialSrc, false); // Check if the image with the partial src was found in image elements and exists if ($imageByPartialSrc && $imageByPartialSrc->is_exist()) { echo "\nFound image with partial src '" . $partialSrc . "':\n"; echo "Image alt: " . $imageByPartialSrc->get_alt() . "\n"; echo "Image inner number: " . $imageByPartialSrc->inner_number . "\n"; echo "Full src: " . $imageByPartialSrc->get_src() . "\n"; } else { echo "\nNo image with partial src '" . $partialSrc . "' found in the collection\n"; } // Try to find an image with a non-existent src in image elements $nonExistentSrc = "nonexistent.jpg"; $imageByNonExistentSrc = $images->get_by_src($nonExistentSrc, true); // Check if the image with the non-existent src was found in image elements and exists if ($imageByNonExistentSrc && $imageByNonExistentSrc->is_exist()) { echo "\nUnexpectedly found image with src '" . $nonExistentSrc . "'\n"; } else { echo "\nAs expected, no image with src '" . $nonExistentSrc . "' found in the collection\n"; } // Display all image srcs in the collection for reference echo "\nAll image srcs in the collection:\n"; for ($k = 0; $k < $images->count(); $k++) { $currentImage = $images->get($k); if ($currentImage && $currentImage->is_exist()) { $imageSrc = $currentImage->get_src(); $imageAlt = $currentImage->get_alt(); echo "Image #" . ($k + 1) . ": Src = '" . $imageSrc . "', Alt = '" . $imageAlt . "'\n"; } } } else { echo "No image 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. Получить все рисунки : ") images=image.get_all() echo(images.get_count(),"<br>") # 3 echo("3. Получим размеры картинки с src = https://rpa-bot.ru/wiki/poligon/screenshots/01.jpg : ") img_01=images.get_by_src("https://rpa-bot.ru/wiki/poligon/screenshots/01.jpg") echo(img_01.get_width()," x ") echo(img_01.get_height(),"<br>") # 4 echo("4. Получим размеры картинки с src, содержащей 02 : ") img_02=images.get_by_src("02",false) echo(img_02.get_width()," x ") echo(img_02.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_src</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("rpa-bot.ru/wiki/poligon/image.html")+"<br>"); // 2 шаг echo("2. Получить все рисунки : "); XHEInterfaces images=image.get_all(); echo(images.get_count()+"<br>"); // 3 шаг echo("3. Получим размеры картинки с src = https://rpa-bot.ru/wiki/poligon/screenshots/01.jpg : "); XHEInterface img_01=images.get_by_src("https://rpa-bot.ru/wiki/poligon/screenshots/01.jpg"); echo(img_01.get_width()+" x "+img_01.get_height()+"<br>"); // 4 шаг echo("4. Получим размеры картинки с src, содержащей 02 : "); XHEInterface img_02=images.get_by_src("02",false); echo(img_02.get_width()+" x "+img_02.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_src</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/image.html")+"<br>"); // 2 шаг echo("2. Получить все рисунки : "); images=image.get_all(); echo(images.get_count()+"<br>"); // 3 шаг echo("3. Получим размеры картинки с src = https://rpa-bot.ru/wiki/poligon/screenshots/01.jpg : "); img_01=images.get_by_src("https://rpa-bot.ru/wiki/poligon/screenshots/01.jpg"); echo(img_01.get_width()+" x "+img_01.get_height()+"<br>"); // 4 шаг echo("4. Получим размеры картинки с src, содержащей 02 : "); img_02=images.get_by_src("02",false); echo(img_02.get_width()+" x "+img_02.get_height()+"<br>"); // конец echo("\n"); // Quit app.quit();
=============================================
Interfaces Объекты DOM System Vision Web Window
=============================================
Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.