Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium页面向下滚动(页面分为两个,2个小标题)_Python_Html_Selenium_Webdriver - Fatal编程技术网

Python Selenium页面向下滚动(页面分为两个,2个小标题)

Python Selenium页面向下滚动(页面分为两个,2个小标题),python,html,selenium,webdriver,Python,Html,Selenium,Webdriver,我正在查看facebook messenger上的对话部分 该页面包含2个滚动条,我希望向下滚动滚动条编号1查看图片 以下是该页面的链接(您应该已登录,并且有25条以上的消息): 我的实际代码: import time from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys opt =

我正在查看facebook messenger上的对话部分

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

以下是该页面的链接(您应该已登录,并且有25条以上的消息):

我的实际代码:

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。向下翻页,结束,向下翻页 箭头键在滚动条1上不起作用

选项1 javascript executor在这种情况下可能会有所帮助,并在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=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);")

谢谢@Amruta,第二个选项效果不错,但它只显示了大约32-42个对话(即使我重复了多次),有没有办法向下滚动更多的对话?滚动等待加载->再次滚动并再次等待->再次滚动(直到有大约100个对话)我认为我从转换列表中提取最后一个元素的选项1b将直接将您带到页面底部。您是否尝试过。在该选项中,您不必进行任何循环。