How to take screenshot of an element

Ask questions here, report about problems.
Post Reply
bryan
Posts: 4
Joined: Wed Mar 27, 2019 7:08 pm

How to take screenshot of an element

Post by bryan » Mon Oct 28, 2019 6:24 pm

Hi,

How to capture the screenshot of a specific element?

I want to capture a part of the page or a specific element based on ID or any specific element locator.

How can I do it in the Human Emulator Studio?

User avatar
support
Site Admin
Posts: 65
Joined: Fri Feb 22, 2019 3:42 pm

Re: How to take screenshot of an element

Post by support » Mon Oct 28, 2019 7:04 pm

Hi,

For to take screenshot a specific element using element ID or any specific element locator you can use following functions with any Human Emulator DOM object:
  • screenshot_by_number – to take screenshot using a specific element number
  • screenshot_by_name – to take screenshot using a specific element name
  • screenshot_by_src – to take screenshot using a specific element src
  • screenshot_by_attribute – to take screenshot using any attribute of specific element
php example:

Code: Select all

$browser->navigate("www.humanemulator.net/poligon/image.html");
$image->screenshot_by_attribute("sc.jpg","name","captcha1",true);
If you want to capture a part of the page then you can use function print_screen of webpage object

print_screen($filepath,$xl=-1,$yt=-1,$xr=-1,$yb=-1,$as_gray=false) - take a screenshot of the current page.
  • filepath - path to the file where the screenshot will be saved (BMP,png,gif,jpeg formats are supported)
  • xl – x-coordinate of the top left corner of the page for the screenshot (at -1-from the beginning of the page)
  • yt – y-coordinate of the top left corner of the page for the screenshot (at -1-from the beginning of the page)
  • xr – x-coordinate of the lower right corner of the page for the screenshot (at -1 - to the end of the page)
  • yb - y-coordinate of the lower right corner of the page for the screenshot (at -1 - to the end of the page)
  • as_gray - specifies to take a screenshot in gray (true), available from version 7.0.6
php example:

Code: Select all

$browser->navigate("https://www.yahoo.com/");

$webpage->print_screen("yahoo.png");
$browser->set_vertical_scroll_pos(100);
$browser->set_horizontal_scroll_pos(100);

$webpage->print_screen("yahoo1.jpeg",200,200,400,400)."<br>";

bryan
Posts: 4
Joined: Wed Mar 27, 2019 7:08 pm

Re: How to take screenshot of an element

Post by bryan » Mon Oct 28, 2019 7:44 pm

Thanks

Post Reply