0
url = correct_url(url)
browser = webdriver.Chrome()
browser.get(url)
browser.find_element_by_xpath('//*[@title="New chat"]').click()
drawer_body = browser.find_elements_by_class_name('drawer-body')
browser.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', drawer_body)

Get the 'div' element, this has a list and will be scrolled

drawer_body = browser.find_elements_by_class_name('drawer-body')

The line below scrolls very fast and reaches the bottom but this does not load data. Is there any way I can slowly scroll into drawer_body element?.

browser.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', drawer_body)

I am trying to implement the below script using python and selenium. http://ctrlq.org/code/19966-whatsapp-phone-numbers

2
  • When you scroll into the drawer_body element it makes a request to the server, you can fetch what request that is. Open the network tab and try to request the link manually and see what happens, if you provide the url I can take a look at it Commented Aug 4, 2016 at 17:28
  • I didn't get what you meant, I am new to these things. I want to scroll in web.whatsapp.com Commented Aug 6, 2016 at 10:05

3 Answers 3

2

Most browsers support Spacebar key as a keyboard shortcut for scrolling page down. Using this feature, you can do the following:

  1. Visit page
  2. Parse what is loaded so far
  3. Simulate press spacebar using Selenium
  4. Wait 2-3 seconds till more data is loaded
  5. Continue

One more hint: to avoid being stuck in a forever loop, you need to implement a check if the newly loaded data differs from the one before pressing spacebar, otherwise the script should quit, as there is no new data to parse.

Sign up to request clarification or add additional context in comments.

Comments

0

try this

drawer_body = browser.find_elements_by_class_name('drawer-body')
location = drawer-body.location
for i in range(location['x']//500):
    browser.execute_script('window.scrollBy(0, 500)')

Comments

0
driver.execute_script('window.scrollBy(0, 500)')
driver.execute_script('window.scrollBy(0, 500)')
time.sleep(2)
driver.execute_script('window.scrollBy(0, 500)')
driver.execute_script('window.scrollBy(0, 500)')
time.sleep(2)
driver.execute_script('window.scrollBy(0, 500)')
driver.execute_script('window.scrollBy(0, 500)')
time.sleep(2)
driver.execute_script('window.scrollBy(0, 500)')
driver.execute_script('window.scrollBy(0, 500)')
time.sleep(2)
driver.execute_script('window.scrollBy(0, 500)')
time.sleep(1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.