I have a method that clicks on a button, however, when it is run, selenium returns the outcome as clicked successfully, when, in reality, the button is not actually clicked. If I run the test several times, occasionally, it'll be clicked as expected. I have my test framework set as an implicit wait for about 15 seconds, I have set an explicit wait for this element, and still see the same issue. When I do <element>.isDisplayed()
, the element is always found. I placed the .click in a while loop to click it a few times which works most of the time, however, still sometimes the test fails. Is it possible to have an if statement to check if an element is actually displayed before clicking the button?
I've tried:
if(!element.isDisplayed){
element.click
}
Here is the button I am having issues with:
<button class="notkoButton listNew">
<div class="l6e iconAdd">New List</div>
</button>
Here is my method:
public marketing_lists_page navigateToNewListPage() throws Throwable {
try {
int x = 0;
while(x < 5) {
newListBtn.click();
x++;
}
//newListPageHeader.isDisplayed();
} catch (NoSuchElementException e){
logs.errorDetails("Could not navigate to New List Page");
Assert.fail();
}
return this;
}