【发布时间】:2019-08-14 05:49:06
【问题描述】:
我正在尝试在填写此网页上的字段后单击继续按钮。但是即使我最大化屏幕并且您可以清楚地看到按钮,也会抛出一个异常说元素不可见。
即使页面等待 10 秒,我也尝试过以下操作:
driver.findElement(By.xpath("//*[@id=\"submitButton\"]/span")).click();
driver.findElement(By.cssSelector("#submitButton > span")).click();
driver.findElement(By.partialLinkText("Continue")).click();
driver.findElement(By.className("caret_rebrand")).click();
driver.findElement(By.name("submitButton")).click();
driver.findElement(By.xpath("//span[contains(@class,'red') and contains(text(), 'Continue')]")).click();
这是我尝试访问的 html 部分:
<button style="padding-left: 0px;" type=button" "id=submitButton" class = "nbutton" title = "Continue" onclick=_hblicnk('continue,'continue'); goFeaturePage('true');">
<span style = "padding-right: 12px;" class="red"
"Continue"
<img class="caret_rebrand">
</span>
我希望找到并单击继续按钮。 attached is the picture of the webpage
更新:8-3-19:我已经测试了以下代码片段,它能够在所有情况下找到元素。但是当将 .click() 函数添加到其中任何一个时,会导致 no such element 异常。
driver.findElement(By.name("submitButton")).click();
driver.findElement(By.id("submitButton")).click();
driver.findElement(By.cssSelector("#submitButton")).click();
driver.findElement(By.xpath("//*[@id=\"submitButton\"]")).click();
【问题讨论】:
-
检查按钮是否存在于 iframe 中。
-
javascript 中有 2 个 iframe 元素,我收到此错误。 org.openqa.selenium.TimeoutException:预期条件失败:等待元素可点击:By.xpath://button[@title='Continue(以 500 毫秒间隔尝试 60 秒)
-
当你说有两个iframe时,如果这个按钮在任何一个iframe下,那么你需要先切换到那个iframe,然后再尝试对该按钮进行操作。
-
我已经在所有 iframe 中测试了该按钮,但单击不起作用导致没有此类元素异常。当我运行以下代码时,它可以找到没有 iframe 的元素,但是当添加 .click() 函数时,它会停止工作。
标签: selenium-webdriver exception button visible