0

Need help with the specific screenshots to take graph screenshots(creating back end by java script) .

I know we can take the element by id, but me getting trouble as new to it.

Tried other way by saving the full screen and cropping it but still getting error with crop function

"TypeError: crop() takes from 1 to 2 positional arguments but 5 were given"

but I can see codes online where four argument can be pass

my codes

enter code here

from selenium import webdriver
from PILLOW import Image
driver = webdriver.Chrome("C:\Selenium_Project\driver\chromedriver")
driver.get('https://python.org')
driver.save_screenshot("screenshot1.png")

im = Image.open('\Selenium_Project\screenshot1.png')

width,height=im.size
left= width/4
top= height/4
right = 3 * width/4
bottom = 3 * height/4

im = im.crop(left, top, right, bottom)

im.save('/Automation_project\Selenium_Project\screenshot1.png')
driver.close()
driver.quit()

If anybody can help witht findelement by id function will also be helpful.

really need help on it guys. cheers

Til
  • 5,150
  • 13
  • 26
  • 34
jfk
  • 1
  • 1
  • found error solution with one extra bracket im = im.crop((left, top, right, bottom)) but still need answer with find element by id to find the size of each element – jfk Apr 15 '19 at 02:57

1 Answers1

0

You can find an element by id with

image = driver.find_element_by_id('myId')

Or

image = driver.find_element_by_css_selector('#myId')

Once you've found it, you can get the element size with

size = image.size
Nathaniel C
  • 524
  • 4
  • 8
  • thanks much,using it , issue is if the element is not current screen (have to scroll to take screenshot ..example driver.execute_script("document.body.style.zoom='60%'") driver.execute_script("window.scrollTo(0, 500)")and then calculate x,y,width,height from there), but like to straight way move in the page location of that element to take screenshot – jfk Apr 16 '19 at 00:54