humanemulator.net — справка.
Продукт, демо и покупка — на
хуманэмулятор.рф
|
Демо
|
Купить
|
API
|
лог изменений
screenshot_by_attribute
screenshot_by_attribute($file_path,$attr_name,$attr_value,$exactly=true,$frame=-1,$as_gray=false); - данная функция используется для создания скриншота элемента страницы, находя его по значению его аттрибутаФункция на вход принимает параметры:
С версии 4.6.41 достпуно: можно передавать вложенные фреймы, принцип такой же самый, передается строка с номерами фреймов, разделенных : например при передаче "1:0:5" - будет выбран фрейм с номером 1 в нем под фрейм с номером 0 и в нем подфрейм с номером 5
С версии 7.0.38 достпуно: можно передавать "url=>XXX", тогда будет произведен поиск фрейма, который содержит заданнй src, или передавать "name=>XXX" - тогда будет поиск фрейма, по заданной части имени.
После отработки функция возвращает результат своей работы в скрипт (тип возвращаемого значения boolean):
Пример использования
<?php // Scenario: Demonstrate the screenshot_by_attribute function for capturing screenshots of DOM elements by their attributes // Connection settings to XHE server $xhe_host = "localhost:7010"; if (!isset($path)){ // Path to the init.php file for connecting to the XHE API $path = "../../../Templates/init.php"; // Including init.php grants access to all classes and functionality for working with the XHE API require($path); } // Navigate to a webpage with elements that have various attributes WEB::$browser->navigate(TEST_POLYGON_URL . "image.html"); WEB::$browser->wait_for(); // Define the path to save screenshots $savePath = "output/element_screenshot.png"; // Example 1: Take a screenshot of an element by its exact attribute value echo "Example 1: Taking a screenshot of an element by exact attribute value<br>\n"; $attrName = "id"; $attrValue = "screen1"; $exactly = true; // Exact match // Take screenshot $screenshotResult = DOM::$image->screenshot_by_attribute($savePath, $attrName, $attrValue, $exactly); // Check the result if ($screenshotResult) { echo "Screenshot saved successfully to: " . $savePath . "<br>\n"; } else { echo "Failed to take screenshot. Element may not exist or error occurred.<br>\n"; } // Example 2: Take a screenshot of an element by partial attribute value echo "\n\nExample 2: Taking a screenshot of an element by partial attribute value<br>\n"; $attrName = "alt"; $attrValue = "screenshot"; // Partial match $exactly = false; // Partial match $savePath2 = "output/element_screenshot_partial.png"; // Take screenshot $screenshotResult = DOM::$image->screenshot_by_attribute($savePath2, $attrName, $attrValue, $exactly); // Check the result if ($screenshotResult) { echo "Screenshot saved successfully to: " . $savePath2 . "<br>\n"; } else { echo "Failed to take screenshot. Element may not exist or error occurred.<br>\n"; } // Example 3: Take a screenshot of an element by attribute in a specific frame echo "\n\nExample 3: Taking a screenshot of an element by attribute in a specific frame<br>\n"; $attrName = "name"; $attrValue = "screen1"; $exactly = true; $frameNumber = 0; // First frame $savePath3 = "output/element_screenshot_frame.png"; // Take screenshot $screenshotResult = DOM::$image->screenshot_by_attribute($savePath3, $attrName, $attrValue, $exactly, $frameNumber); // Check the result if ($screenshotResult) { echo "Screenshot saved successfully to: " . $savePath3 . "<br>\n"; } else { echo "Failed to take screenshot. Element may not exist in the specified frame or error occurred.<br>\n"; } // Quit the application WINDOW::$app->quit(); ?>
# Additional paths import sys sys.path.insert(0, '../../../Templates PY/') xhe_host = "127.0.0.1:7018" from xweb_human_emulator import * # начало echo("<hr><font color=blue>common.xxxxxxxxx</font><hr>") # 1 echo("1. Перейдем на полигон : ") echo(browser.navigate("rpa-bot.ru/wiki/poligon/image.html"),"<br>") # 2 echo("2. Сохранить рисунок c name='captcha1' в файл : ") echo(image.screenshot_by_attribute("c:\\sc.jpg","name","captcha1",true),"<br>") app.shell_execute("open","c:\\sc.jpg") # 3 echo("3. Сохранить несуществующий рисунок по его имени в файл : ") if not image.screenshot_by_attribute("c:\\1.jpg","name","screensh1ot234",true): echo("нет такого рисунка<br>") # 4 echo("4. Сохранить рисунок (упрощенно) c name='captcha1' в файл : ") echo(image.screenshot_by_attribute("c:\\sc2.jpg","name","captcha1",true,-1,true),"<br>") app.shell_execute("open","c:\\sc2.jpg") # конец 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 = "localhost:7010"; InitXHE(); // начало echo("<hr><font color=blue>screenshot_by_attribute</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("rpa-bot.ru/wiki/poligon/image.html")+"<br>"); // 2 шаг echo("2. Сохранить рисунок c name='captcha1' в файл : "); echo(image.screenshot_by_attribute("c:\\sc.jpg","name","captcha1",true)+"<br>"); app.shell_execute("open","c:\\sc.jpg"); // 3 шаг echo("3. Сохранить несуществующий рисунок по его имени в файл : "); if(!image.screenshot_by_attribute("c:\\1.jpg","name","screenshot234",true)) echo("нет такого рисунка<br>"); // 4 шаг echo("4. Сохранить рисунок c name='captcha1' в файл : "); echo(image.screenshot_by_attribute("c:\\2.jpg","name","captcha1",true,"-1",true)+"<br>"); app.shell_execute("open","c:\\2.jpg"); // конец echo("\n\n"); app.quit(); } }
// подключим функциональные объекты, если еще не подключен xhe_host="127.0.0.1:7018"; echo=require("../../../Templates JS/init.js"); // начало echo("<hr><font color=blue>image.screenshot_by_attribute</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("rpa-bot.ru/wiki/poligon/image.html")+"<br>"); // 2 шаг echo("2. Сохранить рисунок c name='captcha1' в файл : "); echo(image.screenshot_by_attribute("c:\\sc.jpg","name","captcha1",true)+"<br>"); app.shell_execute("open","c:\\sc.jpg"); // 3 шаг echo("3. Сохранить несуществующий рисунок по его имени в файл : "); if(!image.screenshot_by_attribute("c:\\1.jpg","name","screenshot234",true)) echo("нет такого рисунка<br>"); // 4 шаг echo("4. Сохранить рисунок (упрощенно) c name='captcha1' в файл : "); echo(image.screenshot_by_attribute("c:\\sc2.jpg","name","captcha1",true,-1,true)+"<br>"); app.shell_execute("open","c:\\sc2.jpg"); // конец echo("\n"); // Quit app.quit();
=============================================
Общие функции Объекты DOM System Vision Web Window
=============================================
Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.
PS: В тестовом примере приведена работа с конкретным объектом DOM, но данная функция есть во всех DOM объектах, т.е она существует у всех объектов из категории DOM.