我想在web.whatsapp.com中滚动聊天。我分享了下面的伪代码:
recentList = driver.find_elements_by_xpath("//div[@class='_2wP_Y']")
driver.execute_script("window.scrollTo(0, 500);")期待一个解决方案,以便在web.whatsapp.com中一直读到最后一次聊天。
提前感谢!
发布于 2017-12-30 03:39:31
尝试下面的代码
recentList = driver.find_elements_by_xpath("//div[@class='_2wP_Y']")
for list in recentList :
driver.execute_script("arguments[0].scrollIntoView();", list )
// other operation发布于 2021-07-21 04:45:31
下面是一个简单的方法,当其他答案都不起作用时,它对我有效。
首先,确保您选择的是带有"scrollbar“元素的div。
scrolling_element= find_element_by_xpath(scrolling_element_xpath)
driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', scrolling_element)发布于 2021-06-18 13:18:07
仅使用Python的解决方案(使用hTouchActions类的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()https://stackoverflow.com/questions/48027558
复制相似问题