最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Selenium: How to scroll in inner div using selenium in python - Stack Overflow

programmeradmin5浏览0评论

Want to scroll the chats in web.whatsapp. 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 till the last chat.

Thanks in advance!

Want to scroll the chats in web.whatsapp.. 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. till the last chat.

Thanks in advance!

Share Improve this question edited Dec 29, 2017 at 20:18 Rohit Rai 3754 silver badges21 bronze badges asked Dec 29, 2017 at 19:35 Alok SaumyaAlok Saumya 691 gold badge1 silver badge7 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 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

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)

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)

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

from selenium.webdriver.mon.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()

element should be a scrollable element

driver.execute_script("arguments[0].scroll(0,arguments[0].scrollHeight);", element)
发布评论

评论列表(0)

  1. 暂无评论