How to force page refresh using selenium webdriver?

In my automation, at some point I have to refresh the page to get the updated contents of the page. But during the update, the web page asks for confirmation to resend the data (basically a warning is displayed on the page).

Despite the fact that I switched the focus to the warning and accepted it, the contents of the page are not updated. If I manually do the same, the contents of the page will be updated.

Is there an alternative way to refresh a page using Selenium Webdriver, other than the navigate () command. refresh ()?

Or is there a way I can click the Retry button in a message without accepting the warning?

+5
source share
2 answers

Page refresh in Selenium Webdriver using Java:

public boolean refresh()
{

    boolean executedActionStatus = false;       
    try{

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

        Thread.sleep(2000);
        executedActionStatus = true;
    }
    catch(Exception er)
    {       
        er.printStackTrace();
        getScreenShot(method_TableName, "ExpCaseShot");
        log.error(er);
    }       
    return executedActionStatus;
}
+2
source

In ruby ​​try using this - @driver.switch_to.alert.accept

click Resend

java code driver.switchTo().alert().accept();

+1
source

All Articles