digital.6
(digital socho)
February 10, 2025, 10:46am
1
Hi Everyone,
I’m using Selenium WebDriver to automate a login process, but the page takes time to load after clicking the login button. How can I ensure my script waits for the elements to be visible before interacting with them? Any suggestions?
Thanks.
Gautam
marcoc_753
(Marco Collovati)
February 10, 2025, 10:52am
2
Tatu2
(Tatu Lund)
February 10, 2025, 5:37pm
3
You can find example from here. After login, I am waiting for suitable indicator element. I have small utility methods in my bade class:
executeScript(
"!!document.activeElement ? document.activeElement.blur() : 0");
}
public void login(String user, String pass) {
var loginForm = $(LoginFormElement.class).first();
loginForm.getUsernameField().setValue(user);
loginForm.getPasswordField().setValue(pass);
blur();
loginForm.getSubmitButton().click();
waitForElementPresent(By.id("app-layout"));
}
public void wait(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
}
}
/**
marcoc_753
(Marco Collovati)
February 10, 2025, 5:42pm
4
Just to clarify: waitForElementPresent
is a Vaadin Testbench helper that under the hood uses Selenium wait
feature.
new WebDriverWait(getDriver(), Duration.ofSeconds(timeoutInSeconds)).until(condition)