Основной сайт хуманэмулятор.рф  |  Демо  |  Купить  |  API  |  Wiki



Window / ui



screenshot

screenshot($path,$x=-1,$y=-1,$width=-1,$heigth=-1,$as_gray=false); - Сделать скриншот UI элемента

Функция на вход принимает параметры:

  • $path – Путь для сохранения скриншота
  • $x – X-координата области (-1 нет отклонения в координате X области)
  • $y – Y-координата области (-1 нет отклонения в координате Y области)
  • $width – Ширина области (-1 нет отклонения в ширине области)
  • $heigth – Высота области (-1 нет отклонения в высоте области)
  • $as_gray – Сохранить в оттенках серого

    После выполнения функции возвращаемое значение будет равно одному из двух :
  • true – успешно
  • false – не удалось

    Пример использования
    <?php
    // Scenario: Demonstrates how to take screenshots of UI elements
    
    $xhe_host = getenv("RPABOT_HOST_URL");
    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);
    }
    
    // Step: Get UI element for interaction
    $windowText = "localhost";
    $xheElement = WINDOW::$window->get_by_text($windowText)->get_ui_element();
    
    // Step: Find a specific element to screenshot (Quick Start button)
    $propertyName = "Name";
    $propertyValue = "Quick Start";
    $quickStartElement = $xheElement->get_by_property($propertyName, $propertyValue);
    
    if ($quickStartElement && $quickStartElement->is_exist()) {
        // Example 1: Take full screenshot of the element
        $screenshotPath1 = "test/screenshot.png";
        $result1 = $quickStartElement->screenshot($screenshotPath1);
        
        if ($result1) {
            echo("Example 1: Successfully took full screenshot\n");
            echo("Screenshot saved to: $screenshotPath1\n");
            
            // Step: Open the screenshot for viewing
            WINDOW::$app->shell_execute("open", $screenshotPath1);
        } else {
            echo("Example 1: Failed to take full screenshot\n");
        }
        
        sleep(2);
        
        // Example 2: Take partial screenshot of the element
        $screenshotPath2 = "test/screenshot.png";
        $partialX = 5;
        $partialY = 5;
        $partialWidth = 45;
        $partialHeight = 12;
        $result2 = $quickStartElement->screenshot($screenshotPath2, $partialX, $partialY, $partialWidth, $partialHeight);
        
        if ($result2) {
            echo("Example 2: Successfully took partial screenshot\n");
            echo("Partial screenshot saved to: $screenshotPath2\n");
            echo("Partial area: x=$partialX, y=$partialY, width=$partialWidth, height=$partialHeight\n");
            
            // Step: Open the partial screenshot for viewing
            WINDOW::$app->shell_execute("open", $screenshotPath2);
        } else {
            echo("Example 2: Failed to take partial screenshot\n");
        }
    } else {
        echo("Example 1: Quick Start element not found\n");
    }
    
    // Quit the application
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7025"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>windowinterface.xxxxxxxxx</font><hr>")
    
    # 1
    echo("1. Скриншот : ");
    xhe=window.get_by_text("localhost").get_ui_element();
    qstart=xhe.get_by_property("Name" , "Быстрый Старт");
    
    echo(qstart.screenshot("test/screenshot.png"));
    
    app.shell_execute("open","test/screenshot.png");
    
    # конец
    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>windowinterface.mouse_right_up</font><hr>");
    				
    			// 1
    			echo("1. Нажать мышь над элементом : ");
    			var xhe=window.get_by_text("localhost").get_ui_element();
    			var qstart=xhe.get_by_property("Name" , "Быстрый Старт");
    			echo(qstart.screenshot("test/screenshot.png"));
    			
    			app.shell_execute("open","test/screenshot.png");
    			
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7025";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>windowinterface.mouse_right_up</font><hr>");
    
    // 1
    echo("1. Нажать мышь над элементом : ");
    var xhe=window.get_by_text("[localhost").get_ui_element();
    var qstart=xhe.get_by_property("Name" , "Быстрый Старт");
    echo(qstart.screenshot("test/screenshot.png"));
    
    app.shell_execute("open","test/screenshot.png");
    
    // ESC
    browser.sleep(2);
    keyboard.key(27);
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    ui    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум
    .