小编典典

Java Selenium-如何在基于AngularJS的页面中单击没有ID或ng-class的按钮

selenium

我使用的以下代码未单击按钮并显示错误
消息。

WebElement clickNextButton = webDriver.findElement(By.cssSelector("button[ng-class='btn-success']"));
clickNextButton.click();

Error message shows “no such element: Unable to locate element.

I’ve also tried the following code segments without success:

  1. WebElement clickNext1 = webDriver.findElement(By.cssSelector(“button[ng-class=’pccCTRL.pow.Page1InputsValid() ? ‘btn-success’ : ‘btn-default’‘]”));
    clickNext1.click();

  2. webDriver.findElement(By.partialLinkText(“Next”)).click();

  3. webDriver.findElement(By.cssSelector(“button[type=’button’]”)).click();

Here is the screenshot showing the html code segment of the button I’m trying
to

Button code
segment

Hoping to get feedback. Thank you.


阅读 413

收藏
2020-06-26

共1个答案

小编典典

好的,我可以使用By.xpath解决此问题

这是解决它的代码段:

WebElement clickNextButton = webDriver.findElement(By.xpath("//button[contains(text(),'Next')]"));

clickNextButton.click();
2020-06-26