如何使用带有 Java 的 Selenium WebDriver 滚动特定的 DIV? [英] How to scroll a specific DIV using Selenium WebDriver with Java?

查看:26
本文介绍了如何使用带有 Java 的 Selenium WebDriver 滚动特定的 DIV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebDriver 无法识别某些 WebElements,WebDriver 无法找到浏览器可见区域中不可见的元素.

Some of WebElements are not recognized by WebDriver, WebDriver fails to find the element which is not visible in browser's visible area.

为了使 WebElement 可被 WebDriver 看到,我们需要使该元素在浏览器视图中可见,以便在特定 div 上向下滚动!

In order to make the WebElement viewable by WebDriver, We need to make that element to visible in browser's view to do scroll down on particular div!

如何在网页的特定区域执行操作(向下滚动并单击).我尝试了很多,对我没有帮助.

How can I perform my action(scroll down and click) on particular area of my webpage. I tried lot, doesn't helped me.

请帮我解决我的问题.

推荐答案

首先,这里发布的大部分答案都与主题无关.我现在一直在使用 selenium 2 和 selenium 3,webdriver 可以处理窗口滚动以使元素可见.

First of all, most of the answers posted here are just off the topic. I have been working with selenium 2 and selenium 3 now, the webdriver can handle window scroll to make an element visible.

对于发布以下片段的每个人:

For everyone posting snippets like:

driver.execute_script('scrollBy(0, 250)')

你根本没有明白这个问题!

you do not get the question at all!

实际上我仍然没有找到一种方法来正确模拟滚动手柄的拖动动作,但是 这个答案 似乎很有希望 -- 但我没有尝试.

Actually I still did not find a way to properly simulate the drag action of scroll handle but this answer seems promising -- but I did not try.

到目前为止,我个人有两种方法可以做到这一点:

So so far personally there are two ways to do this for me:

  1. 使用Keys.ARROW_DOWN
  2. 使用Keys.PAGE_DOWN

其实还有第三种方式,就是放弃selenium,联系网站,如果他们提供任何API.

Actually there is a third way, just give up selenium and contact the website if they provide any API.

这篇关于如何使用带有 Java 的 Selenium WebDriver 滚动特定的 DIV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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