Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh hanging page in Selenium Java Webdriver?

I'm doing some test cases using selenium in Java/Firefox and sometimes the QA server hangs. After clicking the login button, it's still on the same page, doesn't get to the next page, and the loading spinner spins forever. Now my only option so far is to manually refresh even though these are meant to be automated.

I've tried

driver.navigate().refresh();

as well as

((JavascriptExecutor)driver).executeScript("document.location.reload()");

They don't seem to work in-between pages. Is there a better way to refresh the page that does not depend of the state of loading?

like image 903
user1869558 Avatar asked Feb 05 '26 10:02

user1869558


1 Answers

Try to get the URL after imputing details and access it again, basically, you are automating the refresh, for example:

String baseUrl = "sampleweb.com"
driver.get(baseUrl);
driver.findElements(By.cssSelector("username"))
driver.sendKeys("yourusername");
String refresh = driver.getCurrentUrl();
driver.get(refresh);
like image 169
ChavesBR Avatar answered Feb 07 '26 22:02

ChavesBR