1
我目前使用下面的一段代码导航到页面中间,但它不能正常工作。如何使用Python滚动到使用Selenium可见元素的页面位置?
driver.execute_script("window.scrollTo(0, document.body.scrollHeight/2);")
此外,我试图用
element.location_once_scrolled_into_view
有人能帮忙吗?
我目前使用下面的一段代码导航到页面中间,但它不能正常工作。如何使用Python滚动到使用Selenium可见元素的页面位置?
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()
的差异是完全在这里强调: