【问题标题】:Unable to Click button in Selenium无法单击 Selenium 中的按钮
【发布时间】:2019-02-24 20:45:44
【问题描述】:

我很难在页面中找到作为完成按钮的元素。我用过 driver.findElementById("finish").click ();它不起作用。

以下是我使用但没有成功的不同示例:

for (WebElement Element : driver.findElement(By.id("finish")).findElements(By.tagName("a"))) {
if (Element.getAttribute ("class").contains("criteria-filter")) { Element.click();
break;
           }

----------------------------------------------------------------
 WebElement click1 = new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"finish\"]")));   
((JavascriptExecutor) driver).executeScript("arguments[0].click();",click1);

----------------------------------------------------------------

if(!driver.findElementById("finish").isEnabled())
            {
driver.findElementById("finish").click();
 }else{
 System.out.println("False");
            }

元素:

   <a id="finish" access="" allof="PA.DEPLOYMENT_CONFIG" class="btn criteria-filter btn-success" href="" ng-click="verifyAllFields(sftpForm) &amp;&amp; sftpForm.$valid &amp;&amp; create()">Finish 
            </a>

【问题讨论】:

  • 你有什么错误吗?还是 WebElement 可见?
  • 你能分享这个网页,以便人们测试它为什么不工作吗?

标签: java selenium selenium-webdriver xpath css-selectors


【解决方案1】:

类选择器不是最好的主意,因为如果有更多具有相同类的元素,它将失败。

最好的方法是打开 dev-tools,点击 ctrl + f,然后尝试通过 xpath 像这样插入你的元素:

//a[text()='完成']

当你“cath”这个浏览器会移动到那个元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-08
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    相关资源
    最近更新 更多