硒滚动到底部不能正常工作 [英] Selenium scroll to the bottom does not work properly

查看:121
本文介绍了硒滚动到底部不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图滚动到网页的底部,但它只滚动一次并保持该位置,并且有大部分页面已经离开。



我使用这个: _inst.driver.execute_script(window.scrollTo(0,document.body.scrollHeight);)



你知道问题出在哪里吗?

编辑:有没有办法告诉硒它必须滚动到页面的绝对底部或它应该滚动一定的时间?例如5?

解决方案

要滚动到页面底部,可以将CTRL + END发送到其元素之一:

  from selenium.webdriver.common.keys import keys 
element = driver.find_element_by_ ...
element.send_keys(Keys.CONTROL,Keys.END)

要查找元素,可用选项(请参阅此处



请参阅这里获取更多信息



以及这些SO问题/答案:

第一个



secon d


I'm trying to scroll to the bottom of the web page but it scrolls only once and stay on that position and there's a big part of the page left.

I use this: _inst.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

Do you know where could be the problem?

EDIT: Is there a way to tell the selenium that it has to scroll to the absolute bottom of the page or that it should do the scroll certain amount of times? For example 5?

解决方案

To scroll to the bottom of the page, you can send a CTRL+END to one of its elements:

from selenium.webdriver.common.keys import Keys
element = driver.find_element_by_ ...
element.send_keys(Keys.CONTROL , Keys.END)

To find the element, there are many options available (see here)

See here for more info

and these SO questions/answers:

first

second

这篇关于硒滚动到底部不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆