Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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 3.x 在部分网页上使用Python Selenium向下滚动_Python 3.x_Selenium_Selenium Webdriver - Fatal编程技术网

Python 3.x 在部分网页上使用Python Selenium向下滚动

Python 3.x 在部分网页上使用Python Selenium向下滚动,python-3.x,selenium,selenium-webdriver,Python 3.x,Selenium,Selenium Webdriver,所以我有一个网页,其中一部分是用户列表。用户可以向下滚动此列表,但滚动仅在鼠标指针位于此列表上方时有效。像page down或end这样的键不起作用 我可以使用Selenium和Xpath毫无疑问地找到元素,但我不知道如何在Selenium中执行滚动,因为它只在关注特定web元素时才起作用 我试过发送像page down和end这样的键,或者像这样的代码 driver.execute_script("window.scrollTo(0, document.body.scrollHeight);"

所以我有一个网页,其中一部分是用户列表。用户可以向下滚动此列表,但滚动仅在鼠标指针位于此列表上方时有效。像page down或end这样的键不起作用

我可以使用Selenium和Xpath毫无疑问地找到元素,但我不知道如何在Selenium中执行滚动,因为它只在关注特定web元素时才起作用

我试过发送像page down和end这样的键,或者像这样的代码

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

有人有什么想法吗?

因为您提到可以定位元素,您可以尝试滚动到特定元素,而不是使用
document.body.scrollHeight
作为滚动目标

element = driver.find_element(someLocatorHere)

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

希望这能有所帮助。

滚动可以通过两种不同的方式实现

Javascript

 elementId = driver.find_element_by_id("elementId")
 driver.execute_script("arguments[0].scrollIntoView();", elementId)
行动类

actions = ActionChains(driver)
actions.move_to_element(elementId).perform()

你能分享网址吗?这能回答你的问题吗?通过选择可见元素,然后通过actionchains发送结束键,解决了这个问题。