Quantcast
Viewing all articles
Browse latest Browse all 16

Answer by gabriel de la cruz for Webdriver Screenshot in Python

Here they asked a similar question, and the answer seems more complete, I leave the source:

How to take partial screenshot with Selenium WebDriver in python?

from selenium import webdriverfrom PIL import Imagefrom io import BytesIOfox = webdriver.Firefox()fox.get('http://stackoverflow.com/')# now that we have the preliminary stuff out of the way time to get that image :Delement = fox.find_element_by_id('hlogo') # find part of the page you want image oflocation = element.locationsize = element.sizepng = fox.get_screenshot_as_png() # saves screenshot of entire pagefox.quit()im = Image.open(BytesIO(png)) # uses PIL library to open image in memoryleft = location['x']top = location['y']right = location['x'] + size['width']bottom = location['y'] + size['height']im = im.crop((left, top, right, bottom)) # defines crop pointsim.save('screenshot.png') # saves new cropped image

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>