selenium icon indicating copy to clipboard operation
selenium copied to clipboard

Implement WebElement screenshot in InternetExplorerDriver

Open StephenDavidson opened this issue 11 years ago • 13 comments

In selenium py 2.47.1, I am currently unable to take an element screenshot. I have not tested this i

Python version: 2.7.6 Selenium python verison: 2.47.1 Browsers tested: Chrome, Firefox

Script:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://google.com')

el = driver.find_element_by_class_name('gsfi')
el.screenshot('test.png')

driver.quit()

Stacktrace:

Traceback (most recent call last):
  File "/Users/Stephen/Projects/g2m/g2m-free-qa-automation/test.py", line 7, in <module>
    el.screenshot('test.png')
  File "/Users/Stephen/Projects/envs/qa_repo/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 399, in screenshot
    png = self.screenshot_as_png
  File "/Users/Stephen/Projects/envs/qa_repo/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 386, in screenshot_as_png
    return base64.b64decode(self.screenshot_as_base64.encode('ascii'))
  File "/Users/Stephen/Projects/envs/qa_repo/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 376, in screenshot_as_base64
    return self._execute(Command.ELEMENT_SCREENSHOT)['value']
  File "/Users/Stephen/Projects/envs/qa_repo/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 448, in _execute
    return self._parent.execute(command, params)
  File "/Users/Stephen/Projects/envs/qa_repo/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 196, in execute
    self.error_handler.check_response(response)
  File "/Users/Stephen/Projects/envs/qa_repo/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 102, in check_response
    value = json.loads(value_json)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

StephenDavidson avatar Aug 11 '15 09:08 StephenDavidson

This has not been implemented by any of the drivers in the project yet 

— Sent from Mailbox

On Tue, Aug 11, 2015 at 10:50 AM, Stephen Davidson [email protected] wrote:

In selenium py 2.47.1, I am currently unable to take an element screenshot. Python version: 2.7.6 Selenium python verison: 2.47.1 Browsers tested: Chrome, Firefox Script:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://google.com')
el = driver.find_element_by_class_name('gsfi')
el.screenshot('test.png')
driver.quit()

Reply to this email directly or view it on GitHub: https://github.com/SeleniumHQ/selenium/issues/912

AutomatedTester avatar Aug 11 '15 11:08 AutomatedTester

I assumed that this feature had been implemented back in 2.46 based off of the changelog https://github.com/SeleniumHQ/selenium/blob/master/py/CHANGES#L15

StephenDavidson avatar Aug 11 '15 13:08 StephenDavidson

Looking at the changelog @lukeis added support for this in the python client (which makes the changelog correct (kinda)). I only know of one implementation, which is in "alpha" stage with this.

You can see about it in http://www.theautomatedtester.co.uk/blog/2015/another-marionette-release-now-with-windows-support.html and https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver .

Leaving this bug open as we may repurpose to add support for element screenshot to things.

David Burns Email: [email protected] URL: http://www.theautomatedtester.co.uk/

On Tue, Aug 11, 2015 at 2:41 PM, Stephen Davidson [email protected] wrote:

I assumed that this feature had been implemented back in 2.46 based off of the changelog https://github.com/SeleniumHQ/selenium/blob/master/py/CHANGES#L15

— Reply to this email directly or view it on GitHub https://github.com/SeleniumHQ/selenium/issues/912#issuecomment-129877145 .

AutomatedTester avatar Aug 11 '15 15:08 AutomatedTester

@AutomatedTester there's one other that implements it. EdgeDriver.

lukeis avatar Aug 11 '15 16:08 lukeis

essentially this bug should only be left open as to intend to implement it in our open source FirefoxDriver, InternetExplorerDriver and (maybe) SafariDriver

lukeis avatar Aug 11 '15 16:08 lukeis

@StephenDavidson if you would like this availabe in chromedriver, please log a bug with that project: https://code.google.com/p/chromedriver/issues/list

lukeis avatar Aug 11 '15 16:08 lukeis

Since this feature is only available in one actually used driver, and not even in the reference driver, don't you think this should be explicitly stated on at least the pydoc for this feature? This issue is pretty much the only place you can currently find that only the Edge Driver supports it...

rouke-broersma avatar Jun 01 '16 10:06 rouke-broersma

This is in Marionette, the FirefoxDriver replacement and has been since we added the screenshot code nearly 2 years ago.

AutomatedTester avatar Jun 01 '16 14:06 AutomatedTester

With the release of Safari 10, Apple now offers official support WebDriver. Because of this, the Selenium project no supports the legacy implementation from 2.x.

Users are advised to switch to Apple’s driver and file bugs at https://bugreport.apple.com/

lukeis avatar Sep 23 '16 20:09 lukeis

Is this feature going to be implemented any time soon?

dninet avatar Nov 18 '17 22:11 dninet

Firefox allows that, but Chrome does not support element.screenshot() method right now. Is it going to be implemented?

samuraii avatar Jul 04 '18 14:07 samuraii

Thank you for bringing this issue up. Time to close it because element screenshots have been implemented in IE too.

For Chrome follow chromedriver issue tracker: https://bugs.chromium.org/p/chromedriver/issues/list

barancev avatar Jul 07 '18 17:07 barancev

Thank you for bringing this issue up. Time to close it because element screenshots have been implemented in IE too.

For Chrome follow chromedriver issue tracker: https://bugs.chromium.org/p/chromedriver/issues/list

can i get some tips? How to take a element screenshot in IE?

zicjin avatar Mar 27 '19 17:03 zicjin