【问题标题】:Selenium: Scrolling a scroll bar within browser window (not the browser scroll bar)Selenium:在浏览器窗口中滚动滚动条(不是浏览器滚动条)
【发布时间】:2018-08-31 11:58:45
【问题描述】:

我正在尝试在浏览器窗口中滚动。通常你会滚动浏览器的滚动条:

browser.execute_script('window.scrollTo(0, document.body.scrollHeight)')

但这不是我想要做的。在下图中,您将看到我试图向下滚动的滚动条。

查看我要滚动的滚动条的红色箭头:

【问题讨论】:

  • 请阅读为什么screenshot of HTML or code or error is a bad idea。考虑使用基于格式化文本的相关 HTML、代码试验和错误堆栈跟踪来更新问题。
  • 这个问题解决了吗?即使我遇到了同样的问题。我没有通过操作或预期条件找到合适的解决方案

标签: python python-2.7 selenium selenium-webdriver


【解决方案1】:

您可以使用ActionChains 中的move_to_element。找到您要滚动到的元素,move_to_element 将滚动到它

from selenium.webdriver.common.action_chains import ActionChains

element = driver.find_element(...)
ActionChains(driver).move_to_element(element).perform()

【讨论】:

  • 只有在我向下滚动后才能看到和定位元素。即使自定义滚动菜单中的所有元素都遵循某种模式,我也无法找到它
猜你喜欢
  • 2010-09-06
  • 1970-01-01
  • 1970-01-01
  • 2010-11-15
  • 2015-08-11
  • 2018-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多