Selenium:测试其 CSS 属性为“OVERFLOW"的 WebElements是自动/滚动 [英] Selenium : Test WebElements whose CSS attribute "OVERFLOW" is auto/scroll

查看:41
本文介绍了Selenium:测试其 CSS 属性为“OVERFLOW"的 WebElements是自动/滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的页面中,只显示了三个元素,我必须使用滚动条才能看到其他元素.
我正在使用硒网络驱动程序.
当我尝试单击第四行"或第五行"时抛出 ElementNotVisibleException.
是否有任何方法可以移动滚动条(或其他方式?)以使第四行"和第五行"可见,然后可点击?

<b>该元素的源代码:</b><预><html><body><div style="WIDTH: 215px; HEIGHT: 50px; OVERFLOW: auto; background-color:#66FFCC"><ul><li><div>第一行</div></li><li><div>第二行</div></li><li><div>第三行</div></li><li><div>第四行</div></li><li><div>第五行</div></li>

</body></html>

解决方案

好吧,我还没有看到任何 selenium api 可以做到这一点.

但是使用 JavaScriptExecutor 你可以做到这一点.

方法如下

//通过某种方法选择元素WebElement we = driver.findElement(By.id("elementid"));//创建 JSExecutor 对象JavascriptExecutor executor = (JavascriptExecutor)driver;//做JS点击executor.executeScript("arguments[0].click();", we);

In the following page, Only three elements are displayed, I have to use scroll bar to see others.
I'm using selenium webdriver.
ElementNotVisibleException was thrown when I tried to click on the "Fourth Row" or the "Fifth Row".
Is there any method to move the scoll bar(or other way?) to make the "Fourth Row" and the "Fifth Row" visible, then clickable?

<b>Source code of this element:</b>
<pre>
<html><body>
<div style="WIDTH: 215px; HEIGHT: 50px; OVERFLOW: auto; background-color:#66FFCC">
<ul>
<li><div>First Row</div></li>
<li><div>Second Row</div></li>
<li><div>Third Row</div></li>
<li><div>Fourth Row</div></li>
<li><div>Fifth Row</div></li>
</ul>
</div>
</body></html>

解决方案

Well, I haven't seen any selenium api to do this.

But with JavaScriptExecutor you can do this.

Here is how

//Select element by some method

WebElement we = driver.findElement(By.id("elementid"));

// create JSExecutor object

JavascriptExecutor executor = (JavascriptExecutor)driver;

// Do the JS click 

executor.executeScript("arguments[0].click();", we); 

这篇关于Selenium:测试其 CSS 属性为“OVERFLOW"的 WebElements是自动/滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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