Element visible but not yet clickable

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 (VisibilityOfAllElementsLocatedBy).

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

    
asked by anonymous 07.04.2016 / 15:35

1 answer

1

In addition to checking if the element is visible through the method you mentioned you can check if the element can already be clicked through the elementToBeClickable method before calling the click method. Use the wait to wait for the element to get ready. Here's 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();
}
    
29.04.2016 / 23:59