get_by_xpath

get_by_xpath($xpath); - this function is used to get the DOM interface of a page element, finding it by the specified xpath.

Available from version 6.0.47

The input function accepts parameters:

  • $xpath – xpath of the specified element (string).

    After testing, the function returns the result of its work to the script :
  • DOM element interface – an object that allows you to quickly perform any operations with the found element, the return value type XHEInterface

    PHP example: anchor->".basename(__FILE__)."
    "; //1 echo "1.Let's go to the polygon:"; echo $browser->navigate("http://humanemulator.net/poligon/anchor.html")."
    "; //2 echo "2.Get x and y of the element with the given xpath:"; $obj = $anchor->get_by_xpath("/html [1]/body [1]/a [2]"); echo $obj->get_x()."".$obj->get_y(); //end echo "

    "; //Quit $app->quit(); ?>
    Python example: # Additional paths import sys sys.path.insert(0, '../../../Templates PY/') xhe_host = "127.0.0.1:7031" from xweb_human_emulator import * # Start echo("
    common.get_by_src
    ") # 1 echo("1.Let's go to the polygon:") echo(browser.navigate("http://www.humanemulator.net/poligon/image.html"), "
    ") # 2 echo("2.Get x and y from the image with the given xpath and click on it:") obj = image.get_by_xpath("/html/body/p/img") echo(obj.get_x(), "") echo(obj.get_y(), "") echo(obj.click(), "
    ") # end echo("

    ") # 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:7031"; InitXHE(); //Start echo("
    get_by_src
    "); //1 step echo("1.Let's go to the polygon:"); echo(browser.navigate("www.humanemulator.net/poligon/image.html") + "
    "); //step 2 echo("2.Get x and y by xpath:"); XHEInterface obj = image.get_by_xpath("/html [1]/body [1]/img [1]"); echo(obj.get_x() + "" + obj.get_y()); //end echo("

    "); app.quit(); } }
    Java Script example: //connect the object to control the emulator, if not already connected xhe_host = "127.0.0.1:7031"; echo = require("../../../Templates JS/xweb_human_emulator.js"); //Start echo("
    anchor.get_by_src
    "); //1 step echo("1.Let's go to the polygon:"); echo(browser.navigate("http://www.humanemulator.net/poligon/image.html") + "
    "); //step 2 echo("2.Get the x and y of the element with the given xpath:"); obj = image.get_by_xpath("//html [1]/body [1]/img [1]"); echo(obj.get_x() + "" + obj.get_y() + ""); echo(obj.click() + "
    "); //end echo("

    "); //Quit app.quit();