gpt4 book ai didi

java - 令人沮丧的 ElementNotVisibleException 错误

转载 作者:行者123 更新时间:2023-11-30 10:58:27 25 4
gpt4 key购买 nike

当我试图点击一个按钮时出现以下错误:

org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with

命令时长或超时:10.06秒

我尝试了以下方法,但都没有用:

1) 等待 10 秒,以防页面正在加载

2) 这样使用 JS 执行器:

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", By.cssSelector("#IconButton > input.IconButtonDisplay"));

3) 使用等到元素可见

实际上执行了第 2 个,但点击的结果没有发生,即新页面没有打开。

第 3 次说明按钮不可见,但按钮可见且可以手动点击。

我可以告诉你的是,使用 Selenium IDE 我可以播放并点击按钮没有问题。

按钮的HTML(不能在这里放太多作为专有信息)。格式化道歉:

<div widgetid="dijit__WidgetsInTemplateMixin_13" id="dijit__WidgetsInTemplateMixin_13" class="gridxCellWidget">
<div class="IconButton" widgetid="IconButton" id="IconButton" data-dojo-type="ab.cd.ef.gh.IconButton" data-dojo-attach-point="rowBtn1Pt">
<input class="IconButtonDisplay" src="/tswApp/ab/cd/ef/gh/images/edit.png" style="width: 20px;" type="image">
</div>
</div>

最佳答案

在 Javascript 执行器中,您希望传递 WebElement 的实例而不是 By 选择器。所以改变

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", By.cssSelector("#IconButton > input.IconButtonDisplay"));

WebElement element = driver.findElement(By.cssSelector("#IconButton > input.IconButtonDisplay"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);

关于java - 令人沮丧的 ElementNotVisibleException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32239864/

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