I am trying without success to click on a particular button using SELENIUM & JAVA but i am getting this error message:
Expected condition failed: waiting for element to be clickable: By.xpath: //*[@id="documentation"]/div/div[2]/div/button (tried for 10 second(s) with 500 milliseconds interval)
That button has this:
<button type="button" class="btn btn-sm btn-link add-row">Upload FILE</button>
The XPATH is:
//*[@id="documentation"]/div/div[2]/div/div/button
I did this:
WebDriverWait wait10735 = new WebDriverWait(driver,Duration.ofSeconds(10));
JavascriptExecutor executor3735 = (JavascriptExecutor)driver;
WebElement elementCat4735=wait10735.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"documentation\"]/div/div[2]/div/button")));
What am i doing wrong in here?
If you use the xpath:
Should work.
Why this happened?
The problem is that you were using the xpath:
With that xpath what you are doing is:
id="documentation"
As you can see your final element (The button) is depending on several other parent elements to be located. Once one of those parent elements changes, your xpath is not valid anymore.
Is much better to locate your xpath based on the properties of your element itself, not on the elements that surround it.
In this case I used the text of the element.
I don't know if it is possible or not, but if it is possible, a good idea is to talk with developers for using ids for all the elements you will use with your automation. This is a team work!