Scrolling The Custom Scrollbar of a div in selenium python

Viewed 268

I am using Selenium to scrape Contacts from my Whatsapp on Whatsapp Web. To scrape all contacts I need to scroll a div which has a scrollbar but I am unable to scroll down in that div it loads contacts as you scroll down. Tried javascript.excute on document height and also scroll on element. send keys PAGE_DOWN also didn't work.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('window-size=1920x1080')
chrome_options.add_argument('--log-level=3')


driver = webdriver.Chrome(executable_path="driver/chromedriver.exe",options=chrome_options)
driver.get("https://web.whatsapp.com/")
driver.find_element_by_xpath('//*[@title="New chat"]').click() #click on new chat button to open contacts
test2 = driver.find_element_by_xpath("//div[@class='_1c8mz rK2ei']") #this div has an custom scrollbar and should be scrolled down to load more contacts


driver.execute_script('arguments[0].scrollIntoView(true);',test2) #tried this
test2.send_keys(Keys.PAGE_DOWN) # and also this
0 Answers
Related