Reputation: 177
I want to take screenshot of the element. I tried with below mentioned code:
ElementIs=driver.find_element_by_xpath(".//body/img")
ElementIs.screenshot('abc.jpg')
but got error:
File "C:\Python34\lib\site-packages\selenium-2.47.1-y3.4.egg\selenium\webdriver\remote\webelement.py", line 448, in _execute return self._parent.execute(command, params)
File "C:\Python34\lib\site-packages\selenium-2.47.1-y3.4.egg\selenium\webdriver\remote\webdriver.py", line 196, in execute self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium-2.47.1-py3.4.egg\selenium\webdriver\remote\errorhandler.py", line 102, in check_responsevalue = json.loads(value_json)
File "C:\Python34\lib\json\__init__.py", line 318, in loads return _default_decoder.decode(s)
File "C:\Python34\lib\json\decoder.py", line 343, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode raise ValueError(errmsg("Expecting value", s, err.value)) from None ValueError: Expecting value: line 1 column 1 (char 0)
Upvotes: 0
Views: 4216
Reputation: 1129
With Firefox you can:
driver = webdriver.Firefox()
qr = driver.find_element_by_css_selector('.css_class')
qr.screenshot("abc.jpg")
You can use class, id or tags in find_element_by_css_selector.
Upvotes: 1
Reputation: 5113
A couple of problems:
find_elements_by_xpath
returns a list, and you can't request a screenshot on a list. Did you mean find_element_by_xpath
?See my earlier answer on this topic for more background and workarounds.
Upvotes: 3