Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98784

Take screenshot of webelement in Selenium Python and save file

$
0
0

I am trying to take a screenshot of a particular webpage element based on class name. I have followed the methods described in How to take screenshot with Selenium WebDriver, How to screenshot a specified WebElement in Selenium using Python and How to take partial screenshot with Selenium WebDriver in python?

Following are the commands and their errors:

driver.find_element_by_class_name("views-field-body").screenshot("test.png") and driver.find_element_by_class_name("views-field-body").screenshot_as_png

Both times I get the error message as

selenium.common.exceptions.WebDriverException: Message: unknown command: session/75c3765173a9cf726d35afa7978d9b6e/element/0.5926184656216698-3/screenshot

When I try image = driver.find_element_by_class_name("views-field-body").screenshot this commands executes, but the image object comes out as bound method as shown in the quoted text below

bound method WebElement.screenshot of selenium.webdriver.remote.webelement.WebElement (session="75c3765173a9cf726d35afa7978d9b6e", element="0.5926184656216698-3")

How does one save this bound method to image on disk? Why are the commands not executing? Using Python 3.8, if that matters.


Viewing all articles
Browse latest Browse all 98784

Trending Articles