2

I have a site that I want to scroll through using Selenium with Chrome and Python. Before, when I've wanted to scroll down, I've always given the following command:

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

However, this website, for reasons I do not understand, is preventing me from scrolling. Does anyone have any advice?

Here is how to access the page I am having trouble with:

  1. Go to https://shopwoodmans.com
  2. Click "In Store"
  3. Click on any store
  4. Click on any of the "Shop Aisles" options
Faisal Maqbool
  • 121
  • 1
  • 8
Alex Heebs
  • 740
  • 1
  • 8
  • 16
  • please provide your full working code with errors or exception stack trace – Ashish Kamble Oct 16 '18 at 04:42
  • It's not giving me an exception. Selenium takes the **driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")** argument, but then nothing happens. – Alex Heebs Oct 16 '18 at 04:45
  • Code as follows: import time import re from selenium import webdriver from bs4 import BeautifulSoup from selenium.webdriver.support.ui import Select from random import randint chrome_path = r"/Library/Frameworks/Python.framework/Versions/3.7/bin/chromedriver" driver = webdriver.Chrome(chrome_path) driver.get("https://shopwoodmans.com") – Alex Heebs Oct 16 '18 at 04:46
  • And then, manually navigate to the page in question, and try the **driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")** argument. – Alex Heebs Oct 16 '18 at 04:47
  • Possible duplicate of [How can I scroll a web page using selenium webdriver in python?](https://stackoverflow.com/questions/20986631/how-can-i-scroll-a-web-page-using-selenium-webdriver-in-python) – Ashish Kamble Oct 16 '18 at 04:56

1 Answers1

5

If you want to scroll page down to trigger XHR, try below approach

from selenium.webdriver.common.keys import Keys

driver.find_element_by_tag_name('body').send_keys(Keys.END)
Andersson
  • 51,635
  • 17
  • 77
  • 129