Reputation: 111
I am trying to scroll a web page by using mouse and scroll bar. I am exploring any other option than
"driver.execute_script("window.scrollBy(0, 5000'))"
I did try options like chrome actions, however nothing seems to be working. Would need some guidance if anyone has any idea how to solve this.
Upvotes: 2
Views: 1880
Reputation: 193308
If your usecase is to scroll()
the window containing the DOM document, there is no better way other then using the either of the following Window Methods:
If your usecase is to scroll()
an Element there is no better way other then using the Element Method:
You can find a detailed discussion in What is the difference between the different scroll options?
However, if you want to avoid the execute_script()
to interact with a WebElement you have two (2) other options available as follows:
Using move_to_element() from selenium.webdriver.common.action_chains. This method will automatically scroll the element within the Viewport.
Example code:
menu = driver.find_element_by_css_selector(".nav")
hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1")
ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()
Using element_to_be_clickable() from selenium.webdriver.support.expected_conditions. This expected_conditions when used in conjunction with selenium.webdriver.support.wait will automatically scroll the element within the Viewport.
Example code:
WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Cart"))).click()
Upvotes: 2