I need to be able to scroll up and after that down to find some element with Selenium.
I already saw many questions and answers, the main idea I found is self.web_
If you defined driver as webdriver.Chrome()
or webdriver.Firefox()
,you can use this code for scrolling up:
from selenium.webdriver.common.keys import Keys
driver.find_element_by_tag_name('body').send_keys(Keys.HOME)
Also, for scrolling down, you can try this code:
driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", scr1)
scr1
is your box xpath which you want to scroll it.
You can scroll to middle of the page by this code, too:
driver.execute_script("arguments[0].scrollTop = arguments[0].scrollWidth", scr1)