6

In my automation, at one point I have to refresh the page to get the updated page content. But during the refresh the webpage is asking for a confirmation to resend the data (basically an alert is displayed on the page).

Even though I switched the focus to the alert and accepted it, the page contents are not getting refreshed. If I manually do the same, page contents are getting refreshed.

Is there any alternative way to refresh the page using Selenium Webdriver apart from navigate().refresh() command?

Or is there any way I can click on the Retry button on the alert without accepting the alert??

Tad Donaghe
  • 6,625
  • 1
  • 29
  • 64

2 Answers2

2

Refreshing Page 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;
}
tkanzakic
  • 5,499
  • 16
  • 34
  • 41
Chintu
  • 29
  • 2
2

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

this will click on Resend

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

Amey
  • 8,470
  • 9
  • 44
  • 63