How to posiiton an element to the top of a screen/view in appium python web driver

347 Views Asked by At

I am trying to take a screenshot of an element with a certain id using appium python. I want the element to be on the top of the screen so that I can grab the maximum content of that element. Currently, it takes a screenshot even if the element is at the very bottom, because of which I dont get to see the content.

1

There are 1 best solutions below

0
On

It's quite confusing about your question, but from what I understand, you need to scroll the page so that the element is on top of the screen?

If so, try executing this script to your element, the element should be at top of your page now.

elem = driver.find_element_by_name("q")
driver.execute_script("arguments[0].scrollIntoView();", elem)

You can also try move_to_element then move_by_offset of page height but I don't recommend this.


If you want to take screenshot of full content of element, why not try:

elem.screenshot("foo.png")

screenshot method