User Tools

Site Tools


Sidebar

en:objects:common:screenshot:screenshot_by_src

screenshot_by_src

screenshot_by_src($file_path,$src,$exactly=true,$frame=-1,$as_gray=false); - this function is used to create a screenshot of a page element, finding it by the specified src or part of it.

the input Function accepts parameters:

  • $file_path – path to the file where the screenshot of the element will be saved. By default, the screenshot format is jpeg. The following screenshot file formats are also supported (set by the file extension): bmp,gif,png. The path to the file can be full (with the disk specified) so the relative path will be added to the folder where the php file of the running script is located.
  • $src – src by which we find the element we need on the page (string). To find out the src of an element, you can use either the element inspector or the context menu, or view it in the list of elements.br>
  • $exactly – exact match src when searching for a element (boolean), default 1 - src element must match exactly with the passed parameter ($src), if this parameter is specified as 0 then the first item in src which contains the given string ($src). Starting from version 7.0.25, you can fart the value 2, then src will be interpreted as a regular expression for the Java Script String.search function.
  • $as_gray – specifies to take a screenshot in gray (true), available from version 7.0.6
  • $frame – the number of the frame in which we are looking for the element (string). Frame numbers start from zero. By default, -1 - the element is not in the frame. You can find out the number of the frame that contains the item you need from the task inspector, the context menu, and the item list panel.
    With version 4.6.41 of postpone: you can pass nested frames, the principle is the same, a string is numbered frames separated by : for example, if you transfer "1:0:5" - will the selected frame number 1 in it under the frame with the number 0 and the subframe number 5
    Since version 7.0.38, you can pass "url=>XXX", then search for the frame that contains the specified src, or pass "name=>XXX" - then the frame will be searched by the specified part of the name.

    After the function returns the result of their work in the script (the return value type is boolean):
  • true – executed successfully
  • false to find this element failed (e.g. no items that meet the specified criteria or not this frame)

    PHP example:

    <?php $xhe_host = "127.0.0.1:7013";
     
    //connect the object to control the emulator, if not already connected !!!
    if(!isset($path))
      $path = "../../../Templates/xweb_human_emulator.php";
    require($path);
     
    //Start
    echo "<hr> <font color = blue> image->".basename(__FILE__)."</font> <hr>";
     
    //1
    echo "1.Let's go to the polygon:";
    echo $browser->navigate("http://humanemulator.net/poligon/image.html")."<br>";
     
    //2
    echo "2.Screenshot of the src image to file:";
    echo $image->screenshot_by_src("test \ test.jpg", "http://www.humanemulator.net/screenshots/02.jpg")." n";
    $app->shell_execute("open", "test \ test.jpg");
     
    //3
    echo "3.Screenshot of a nonexistent picture to a file:";
    if(!$image->screenshot_by_src("test \ test.jpg", 100500))
      echo "no such picture <br>";
     
    //4
    echo "4.Screenshot of the src image to file:";
    echo $image->screenshot_by_src("test \ test1.jpg", "http://www.humanemulator.net/screenshots/02.jpg", false, -1, true)." n";
    $app->shell_execute("open", "test \ test1.jpg");
     
    //five
    echo "5.Screenshot of the picture via src to a file in frame 0:";
    echo $image->screenshot_by_src("test \ test2.jpg", "http://humanemulator.net/screenshots/02.jpg", false, 0, true)." n";
    $app->shell_execute("open", "test \ test2.jpg");
     
    //end
    echo "<hr> <br>";
     
    //Quit
    $app->quit();
    ?>

    Python example:

    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
     
    xhe_host = "127.0.0.1:7018"
    from xweb_human_emulator import *
     
    # Start
    echo("<hr> <font color = blue> common.xxxxxxxxx </font> <hr>")
     
    # 1
    echo("1.Let's go to the polygon:")
    echo(browser.navigate("http://www.humanemulator.net/poligon/image.html"), "<br>")
     
    # 2
    echo("2.Screenshot of the src image to file:")
    echo(image.screenshot_by_src("test \ sc.jpg", "http://www.humanemulator.net/screenshots/02.jpg"), "
    ")
    app.shell_execute("open", "c: \ sc.jpg")
     
    # 3
    echo("3.Screenshot of a nonexistent picture to a file:")
    if not image.screenshot_by_src("test \ test.jpg", 100500):
      echo("no such picture <br>")
     
    # 4
    echo("4.Screenshot of src image to file:")
    echo(image.screenshot_by_src("test \ sc2.jpg", "http://www.humanemulator.net/screenshots/02.jpg", -1, true), "
    ")
    app.shell_execute("open", "c: \ sc2.jpg")
     
    # end
    echo("<hr> <br>")
     
    # Quit
    app.quit()

    C# example:

    #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 = "127.0.0.1:7018";
    InitXHE();
     
    //Start
    echo("<hr> <font color = blue> screenshot_by_src </font> <hr>");
     
    //1 step
    echo("1.Let's go to the polygon:");
    echo(browser.navigate("www.humanemulator.net/poligon/image.html") + "<br>");
     
    //step 2
    echo("2.Save the picture by its src to file:");
    echo(image.screenshot_by_src("c: \ sc.jpg", "http://humanemulator.net/images/captcha.jpg", true) + "<br>");
    app.shell_execute("open", "c: \ sc.jpg");
     
    //step 3
    echo("3.Save the src image to file:");
    echo(image.screenshot_by_src("c: \ sc1.jpg", "screen", false) + "<br>");
    app.shell_execute("open", "c: \ sc1.jpg");
     
    //step 4
    echo("4.Save a non-existent picture by its src to a file:");
    if(!image.screenshot_by_src("c: \ 1.jpg", "screenshot234"))
    echo("no such picture <br>");
     
    //step 5
    echo("5.Save the picture by its src to a file(simplified):");
    echo(image.screenshot_by_src("c: \ sc.jpg", "http://humanemulator.net/images/captcha.jpg", true, "-1", true) + "<br>");
    app.shell_execute("open", "c: \ sc.jpg");
     
    //end
    echo("<hr> <br>");
     
    app.quit();
    }
    }

    Java Script example:

    //connect the object to control the emulator, if not already connected
    xhe_host = "127.0.0.1:7018";
    echo = require("../../../Templates JS/xweb_human_emulator.js");
     
    //Start
    echo("<hr> <font color = blue> image.screenshot_by_src </font> <hr>");
     
    //1 step
    echo("1.Let's go to the polygon:");
    echo(browser.navigate("www.humanemulator.net/poligon/image.html") + "<br>");
     
    //step 2
    echo("2.Save the picture by its src to file:");
    echo(image.screenshot_by_src("c: \ sc.jpg", "http://humanemulator.net/images/captcha.jpg", true) + "<br>");
    app.shell_execute("open", "c: \ sc.jpg");
     
    //step 3
    echo("3.Save the src image to file:");
    echo(image.screenshot_by_src("c: \ sc1.jpg", "screen", false) + "<br>");
    app.shell_execute("open", "c: \ sc1.jpg");
     
    //step 4
    echo("4.Save a non-existent picture by its src to a file:");
    if(!image.screenshot_by_src("c: \ 1.jpg", "screenshot234"))
      echo("no such picture <br>");
     
    //step 5
    echo("5.Save the picture by its src to a file:");
    echo(image.screenshot_by_src("c: \ sc2.jpg", "http://humanemulator.net/images/captcha.jpg", true, -1, true) + "<br>");
    app.shell_execute("open", "c: \ sc2.jpg");
     
    //end
    echo("<hr> <br>");
     
    //Quit
    app.quit();
  • en/objects/common/screenshot/screenshot_by_src.txt · Last modified: 2026/08/05 22:34 (external edit)