I tried using Explicit Wait with different conditions but none works. In addition, I tried with JavascriptExecutor but here also the element was not clicked. In the case of the code below, the element is not clicked even though the .click() command is used
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#gwt-uid-6")));
driver.findElement(By.cssSelector("#gwt-uid-6")).click();
And in the case of the one below with the use of Thread.sleep the .click() command is executed correctly
Thread.sleep(8000);
driver.findElement(By.cssSelector("#gwt-uid-6")).click();
HTML Code
<li class="v-action" id="gwt-uid-69" aria-labelledby="gwt-uid-68" tabindex="0" style=""><span class="v-icon icon-add-item"></span><span class="v-text" id="gwt-uid-68" for="gwt-uid-69">Add page</span></li>
What is causing this and what other way than Thread.sleep can this problem be solved?
Given the HTML:
The id attribute values like
gwt-uid-69,gwt-uid-68are dynamically generated and is bound to change sooner/later. They may change next time you access the application afresh or even while next application startup. So can't be used in locators.Solution
As the element is a GWT enabled element so to click on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:
Using cssSelector:
Using xpath: