-1
public void addCustInfo() throws InterruptedException
{   
    WebDriver driver;
    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
    driver.get("http://www.way2automation.com/angularjs-protractor/banking/#/manager");
    Thread.sleep(3000);
    driver.findElement(By.xpath("//button[@ng-click='addCust']")).click();
}

I have tried with both relative and absolute xpath, but it doesnt identify in script.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

1

Actually @ng-click value contains function call "...()"

Try to add it

"//button[@ng-click='addCust()']"
DonnyFlaw
  • 581
  • 3
  • 9
0

The value of ng-click attribute isn't addCust but addCust().

So to click() on the element you can use either of the following Locator Strategies:

  • cssSelector:

    driver.findElement(By.cssSelector("button[ng-click^='addCust']")).click();
    
  • xpath:

    driver.findElement(By.xpath("//button[starts-with(@ng-click, 'addCust')]")).click();
    

However, as the element is a dynamic element so to identify the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button[ng-click^='addCust']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[starts-with(@ng-click, 'addCust')]"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You can also use contains inside locator:

  • By XPATH

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(@ng-click, 'addCust')]"))).click();
WKOW
  • 346
  • 2
  • 9