[英]python scroll a specific scrollbar vertically
我正在使用 python selenium 滚动网页,我试图通过单击滚动元素到达页面底部,但它返回此错误: MoveTargetOutOfBoundsException: move target out of bounds
到目前为止我的代码:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
scrollbar_needed = driver.find_element_by_xpath("//div[@class='antiscroll-scrollbar antiscroll-scrollbar-vertical antiscroll-scrollbar-shown']")
actions.click_and_hold(scrollbar_needed).move_by_offset(0,5000).release().perform()
还有另一种使用“scrollbar_needed”路径滚动的方法吗?
有几种滚动浏览动态网页的方法。
选项 1:如果你想滚动一个特定的限制,你可以使用这个
driver.execute_script("window.scrollTo(0, 1000);")
选项 2:如果你想滚动并到达页面末尾,你可以使用这个
driver.find_element(By.TAG_NAME,'body').send_keys(Keys.END)
选项 3:如果它是延迟加载页面,您也可以使用该选项。
# Get scroll height
last_height = driver.execute_script("return document.body.scrollHeight")
limit=500
while True:
# Scroll down to to a limit
driver.execute_script("window.scrollTo(0," + limit + ");")
# Wait to load page
time.sleep(1)
# increase the scroll height
limit=limit+500
# Calculate new scroll height and compare with last scroll height
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
这里是:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.