Visible but not yet clickable element

Asked

Viewed 1,614 times

1

In my automated tests with Selenium, I have a method that waits for the element for a certain time, until the element is visible on the screen (Visibilityofallelementslodby).

However, when the element becomes visible it is not yet clickable, popping the error in the click. It usually happens when you load the element, but the page is still loading.

  • When I say "not yet clickable" I mean enabled to Click. In my case is the label Click in front of the screen

1 answer

1

In addition to checking if the element is visible through the method you quoted you can check whether the element can already be clicked through the elementToBeClickable method before calling the click method. Use Wait to wait for the element to be ready. See an example:

private static WebDriver driver;
private static WebDriverWait wait;

driver = new chromeDriver();
wait = new WebDriverWait(driver, 10); //espera por dez sengundos


static By button = By.id("btnEnviar"); 

public static void clickButton{
    wait.until(ExpectedConditions.visibilityOfElementLocated(button));
    wait.until(ExpectedConditions.elementToBeClickable(button));
    driver.findElement(button).click();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.