Estevao FPM
Estevao FPM

Reputation: 111

Explicit Waits on a given action (error) - Selenium Webdriver

Good morning guys!

I have a problem with my automation using Selenium Webdriver (JAVA). Firstly, the system (interface) uses AJAX, ok?!

I have to click the same button several times. This button remains with the same element.

In order to avoid errors (ElementClickInterceptedException and/or StaleElementReferenceException), i initially added a WebdriverWait with the exception "elementToBeClickable". However, even with this wait, the error remained.

Then I decided to add FluentWait. I added the exceptions, time, etc., but also kept the error.

The only alternative I found to work was the famous "Thread.sleep" (400ms).

But I would not like to add thread.sleep to my code, because I find it a bad practice.

Does anyone have any ideas?

Below are some code snippets.

Command: driver.findElement (By.xpath ("// tr [1] / td [8] / button")). click ();

Waits already used:

1:

wait.until (ExpectedConditions.elementToBeClickable (By.xpath ("// tr / td [8] / button")));

2:

wait.until (ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath ("// tr / td [8] / button")));

3:

                .withTimeout (10, TimeUnit.SECONDS)
                .pollingEvery (1, TimeUnit.SECONDS)
                .ignoring (NoSuchElementException.class)
                .ignoring (StaleElementReferenceException.class)
                .ignoring (ElementClickInterceptedException.class);
waitFluent.until (ExpectedConditions.elementToBeClickable (By.xpath ("// tr / td [8] / button")));

Can anybody help me? Thank you very much in advance!

Upvotes: 0

Views: 235

Answers (1)

Debjit Mukherjee
Debjit Mukherjee

Reputation: 26

Could you please upload the html source code of the application also with your question? And also check whether that button element is inside any iframe tag or not, if so then you have to implement driver.switchTo().frame(iFrame).

Upvotes: 0

Related Questions