简体   繁体   English

python + selenium + chromedriver 如何使用鼠标滚轮?

[英]How can python + selenium + chromedriver use mouse wheel?

There is a <ul> tag in a webpage, and so many <li> tags in the <ul> tag.网页中有一个<ul>标签, <ul>标签中有很多<li> <ul>标签。 The <li> tags are loaded by ajax automatically while mouse wheel scroll down continuously. <li>标签由 ajax 自动加载,同时鼠标滚轮不断向下滚动。

The loading of <li> tags will work well if I use mouse wheel.如果我使用鼠标滚轮, <li>标签的加载会很好地工作。

I want to use selenium to get the loaded info in <li> tags, but the javascript of:我想使用 selenium 来获取<li>标签中加载的信息,但是 javascript:

document.getElementById(/the id of ul tag/).scrollTop=200;

can not work as the new <li> can not be loaded by ajax neither in chrome console nor the selenium execute_script .不能工作,因为新的<li>不能在 chrome 控制台和 selenium execute_script被 ajax 加载。

So, if there is an API of selenium to behave like mouse wheel scroll down?那么,是否有 selenium 的 API 表现得像鼠标滚轮向下滚动? Or is there any other way to solve this problem?或者有没有其他方法可以解决这个问题?

I'd look at the ajax load event listener (the code that loads more <li> s).我会查看 ajax 加载事件侦听器(加载更多<li>的代码)。 You need to trigger whatever that listens for.您需要触发监听的任何内容。 (aka: does it watch for something entering the view port, or something's y-offset, or a MouseEvent , or a scroll() ?) (又名:它是否监视进入视口的东西,或者东西的 y 偏移量,或者MouseEvent ,或者scroll() ?)

Then you need to trigger that kind of event on the element it listens to.然后你需要在它监听的元素上触发那种事件。

从现在开始,没有任何合理的理由,所以我关闭了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM