In Selenium Webdriver ExpectedCondition.elementToBeClickable does not wait until the progress bar disappears

This question is similar to the one below:
i.e. how to wait until the progress bar disappears.
How to dynamically wait for the download indicator to fully load in Selenium Webdriver?

My situation is a little different. In my scenario, all items are disabled when a progress bar appears. I use explicit wait, but still get an exception.

Scenario: After providing all the details on the registration page, the script clicks the "Create Account" button. At this point, a circular progress bar appears, which remains for 1 or 2 seconds. If the entered password is invalid, an error message is displayed at the top of the registration page. Now I need to click on the "Cancel" button and repeat the process.

When a progress bar appears, the entire page turns off. The user can continue only after the progress bar disappears.

Here is my code:

WebDriverWait myWaitVar = new WebDriverWait (driver, 20);

" " . "".

//Click on the "Create Account" button.
driver.findElement(By.id("createAccount")).click();

//Wait till the "Cancel" button shows up -- this may take some time.
myWaitVar.until(ExpectedConditions.elementToBeClickable (By.id("cancelRegister")));

//Click on the "Cancel" button.
driver.findElement(By.id("cancelRegister")).click();

, NoSuchElementException .

ExpectedCondition.visibilityOfElement() NoSuchElementException.

- :

Thread.sleep(3000);

.

WebDriverWait , ? elementToBeClickable() "".

+6
2

ExpectedConditions.elementToBeClickable , , , , , , , : -

//Click on Create Account btn:
driver.findElement(By.id("createAccount")).click();

//Wait till "Cancel" button is showing up. At cases, it may take some time.
WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(By.id("cancelRegister")));
el.click();

Edited1: - - , JavascriptExecutor , :

//Click on Create Account btn:
driver.findElement(By.id("createAccount")).click();

//Wait till "Cancel" button is showing up. At cases, it may take some time.
WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(By.id("cancelRegister")));
((JavascriptExecutor)driver).executeScript("arguments[0].click()", el); 

Edited2: - , cancelRegister. , cancelRegister, :

//Click on Create Account btn:
driver.findElement(By.id("createAccount")).click();

//Now wait for invisibility of progress bar first 
myWaitVar.until(ExpectedConditions.invisibilityOfElementLocated(By.id("page_loader")));

//Now wait till "Cancel" button is showing up. At cases, it may take some time.
WebElement el = myWaitVar.until(ExpectedConditions.elementToBeClickable(By.id("cancelRegister")));
el.click();

, ...:)

+5

, , .

Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
   .withTimeout(30, SECONDS)
   .pollingEvery(5, SECONDS)
   .ignoring(NoSuchElementException.class);

WebElement foo = wait.until(new Function<WebDriver, WebElement>() {
 public WebElement apply(WebDriver driver) {
   return (driver.findElements(By.id("progressbar")).size() == 0);
 }
});
+2

Source: https://habr.com/ru/post/1649621/


All Articles