5

Want to scroll the chats in web.whatsapp.com. Have shared the pseudo-code below:

recentList = driver.find_elements_by_xpath("//div[@class='_2wP_Y']")
driver.execute_script("window.scrollTo(0, 500);")

Looking forward for a solution so as to scoll in web.whatsapp.com till the last chat.

Thanks in advance!

5 Answers 5

8

try below code

recentList = driver.find_elements_by_xpath("//div[@class='_2wP_Y']") 

for list in recentList :
    driver.execute_script("arguments[0].scrollIntoView();", list )
    // other operation
Sign up to request clarification or add additional context in comments.

3 Comments

do you have solution to scroll till the last chat?
The last chat is the last element in the recentList collection. There's no need to scroll through each of the elements in the collection in a loop, only the last.
Try changing list to list[:-1] for the last chat.
1

Try this:

eula = driver.find_elements_by_xpath("//div[@class='_2wP_Y']") 

for my_xpath in eula:
    driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', my_xpath)
    time.sleep(1)

1 Comment

Please expand on this answer to provide some more context
1

Below is a simple approach which worked for me when none of the other answers did.

First make sure you are selecting the div with the "scrollbar" element.

scrolling_element= find_element_by_xpath(scrolling_element_xpath)    
driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', scrolling_element)

Comments

0

Solution with Python only (using hTouchActions class' scroll_from_element method):

from selenium.webdriver.common.touch_actions import TouchActions

recent_list = driver.find_elements_by_xpath("//div[@class='_2wP_Y']")
touch_action = TouchActions(driver)
touch_action.scroll_from_element(recent_list[1], 0, 150).perform()

Comments

0

element should be a scrollable element

driver.execute_script("arguments[0].scroll(0,arguments[0].scrollHeight);", element)

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.