Python Selenium Page Scroll Down(页面一分为二,2个scollers)

Python Selenium Page Scroll Down (the page is divided in two, 2 scollers)

我想向下滚动 facebook messenger 上的对话部分。

该页面包含 2 个滚动条,我想向下滚动 1 号滚动条查看图片

这是页面的link(您应该已登录并且有超过 25 条消息):https://www.facebook.com/messages/t/

我的实际代码:

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

opt = Options()
opt.add_argument("--disable-infobars")
opt.add_argument("start-maximized")
driver = webdriver.Chrome('chromedriver path', options=opt)

# go to fb
driver.get("https://www.facebook.com/")
time.sleep(5)

# login to fb
email = driver.find_elements_by_xpath("//input[@name='email']")
email.sendkeys("youremail")
pass = driver.find_elements_by_xpath("//input[@name='pass']")
pass.sendkeys("yourpassword")
time.sleep(3)

# go to facebook messenger
driver.get("https://www.facebook.com/messages/t/")

# this is what i've tried but didn't work
# start scroling
html = driver.find_element_by_tag_name('html')
html.send_keys(Keys.END)

我们有很多向下滚动的选项,但我检查了 fb manually.Page down ,end ,down 箭头键在滚动条 1 上不起作用。

选项 1 javascript 执行人可能会在这种情况下提供帮助,并在您的 Messenger 中使用您好友的姓名。

element=driver.find_element_by_xpath('//span[contains(text(),'nameofyourbuddy')]//ancestor-or-self::div[position()=3]')

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

或使用 element

滚动到底部页面
element=driver.find_element_by_xpath("//*[@aria-label='Conversation List']/child::*[last()]")
driver.execute_script("arguments[0].scrollIntoView();", element)

如果您没有任何特定元素可向下滚动,选项 2 滚动到页面底部

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")