【发布时间】:2018-03-25 15:40:06
【问题描述】:
我目前正在使用以下代码导航到页面中间,但它无法正常工作。
driver.execute_script("window.scrollTo(0, document.body.scrollHeight/2);")
另外,我正在尝试使用
element.location_once_scrolled_into_view
有人可以帮忙吗?
【问题讨论】:
我目前正在使用以下代码导航到页面中间,但它无法正常工作。
driver.execute_script("window.scrollTo(0, document.body.scrollHeight/2);")
另外,我正在尝试使用
element.location_once_scrolled_into_view
有人可以帮忙吗?
【问题讨论】:
您可以在脚本中调用.scrollIntoView(),将元素作为参数传递:
driver.execute_script("arguments[0].scrollIntoView();", element)
还有move_to_element()内置硒动作:
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(element).perform()
这里完美地突出了差异:
【讨论】: