0

I try to locate a dynamic button element after click search but it cannot locate it. The Create Account CID sometimes is not clickable and sometime can click.

<div class="pzbtn-rgt" data-click="...">
<div class="pzbtn-mid" data-click="....">
<img src="https://10.204.137.86:5111/prweb/PRWebLDAP3/SstGGrXNazw%5B*/webwb/zblankimage.gif" alt="" class="pzbtn-i">
Create Individual CID
<img alt="" src="https://10.204.137.86:5111/prweb/PRWebLDAP3/SstGGrXNazw%5B*/webwb/zblankimage.gif" class="pzbtn-i">

The create individual CID is the one need clicks on. I using absolute xpath but it still fails. I had tried with many ways. Please help. Thanks.

WebDriverWait waitCIDBtn = new WebDriverWait(driver, 10);
waitCIDBtn.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[3]/div[4]/div/div/form/div[1]/div/div/div/div/div[1]/table/tbody/tr/td/div[2]/table/tbody/tr/td/div/div/span/div/div[4]/div/div/div/div[4]/div/div/span/button/div/div/div/div")));
WebElement createCID = driver.findElement(By.xpath("/html/body/div[3]/div[4]/div/div/form/div[1]/div/div/div/div/div[1]/table/tbody/tr/td/div[2]/table/tbody/tr/td/div/div/span/div/div[4]/div/div/div/div[4]/div/div/span/button/div/div/div/div"));
createCID.click();
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
nicholas
  • 2,581
  • 14
  • 66
  • 104

1 Answers1

0

As you are trying to invoke click() on the element so, instead of using visibilityOfElementLocated() you need use elementToBeClickable() and you can use either of the following Locator Strategies:

  • Using cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.pzbtn-mid>img.pzbtn-i[src*='zblankimage']"))).click();
    
  • Using xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='pzbtn-mid']/img[@class='pzbtn-i' and contains(@src, 'zblankimage')]"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Great , can you update the question with your current code trials and error stack trace please? – undetected Selenium Apr 02 '19 at 02:29
  • org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.cssSelector: div.pzbtn-mid>img.pzbtn-i[src*='zblankimage'] (tried for 20 second(s) with 500 milliseconds interval) – nicholas Apr 02 '19 at 02:32
  • The element is not visible at first but after search then it will visible. – nicholas Apr 02 '19 at 02:32
  • @nicholas _TimeoutException_ is the outcome of **failed** _ExpectedConditions_. Debug your code through `findElement()` inconjunction with `Thread.sleep()`. If you are able to locate the element, update the question with the observations. – undetected Selenium Apr 02 '19 at 02:37