Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I have searched a lot for this but couldn't find a solution. There are possible solutions for JAVA. Is there a similar solution in Python?

1 Answer

0 votes
by (62.9k points)

Other than Selenium this example also requires the PIL Imaging library. Sometimes this is put in as one of the standard libraries and sometimes it’s not, but if you don’t have it you can get it here

Other than Selenium this example also requires the PIL Imaging library. Sometimes this is put in as one of the standard libraries and sometimes it’s not, but if you don’t have it you can get it here

from selenium import webdriver

from PIL import Image

fox = webdriver.Firefox()

fox.get('https://intellipaat.com/')

# now that we have the preliminary stuff out of the way time to get that image :D

element = fox.find_element_by_xpath('//a[@class='logo_link']//img[@class='lazyloaded']') # find part of the page you want image of

location = element.location

size = element.size

fox.save_screenshot('screenshot.png') # saves screenshot of entire page

fox.quit()

im = Image.open('screenshot.png') # uses PIL library to open image in memory

left = location['x']

top = location['y']

right = location['x'] + size['width']

bottom = location['y'] + size['height']

im = im.crop((left, top, right, bottom)) # defines crop points

im.save('screenshot.png') # saves new cropped image

I hope, this helps!

 

Browse Categories

...