Not able to scroll down by selenium python

Viewed 102

I'm trying to scrape a website for an about 2 days, but scrolling down to get more elements is the problem. I've almost checked every javascript code in stackoverflow to do that, but none of them worked. For example :

  • window.scrollTo(1, 1000)
  • window.scrollTo(0, document.body.scrollHeight);
  • arguments[0].scrollIntoView(true);

I even used this article, but it didn't work either.

I checked the network to see if I can find the API to use requests to get more elements, but I couldn't find it.

All I want to do is to get more elements, so is there a way to do that?

2 Answers

Try this approach to scroll page down:

from selenium.webdriver.common.keys import Keys

driver.find_element('xpath', '//body').send_keys(Keys.END)

For me the following worked (move_to_element):

from selenium.webdriver import ActionChains
your_link = driver.find_elements(By.XPATH, "//*[contains(@class, 'ClassName')]"
action = ActionChains(driver)
action.move_to_element(your_link).perform()
Related