gpt4 book ai didi

java - Selenium : Test WebElements whose CSS attribute "OVERFLOW" is auto/scroll

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:16:30 26 4
gpt4 key购买 nike

在下面的页面中,只显示了三个元素,我必须使用滚动条才能看到其他元素。
我正在使用 Selenium 网络驱动程序。
当我试图点击“第四行”或“第五行”时抛出 ElementNotVisibleException。
有什么方法可以移动滚动条(或其他方式?)使“第四行”和“第五行”可见,然后可点击?
WebElement with scoll bar

<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>

最佳答案

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

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

方法是这样的

//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);

关于java - Selenium : Test WebElements whose CSS attribute "OVERFLOW" is auto/scroll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19514256/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com