Wednesday, September 12, 2012

Refresh a page with Postback and Re-submit the form

In one of the applications, the page was doing a postback on a huge data set and sometimes it used to time-out in the Staging environment. The behavior was seen very rarely in Production environment. The application itself stored the data every 8 seconds in a temp table so there was no loss of data. But, from the automation script perspective, I had to write code to refresh the page and do the post-back again if it failed the first time (see below).


Refresh any page using Webdriver and Click "OK" on the pop-up / alert box:
               
driver.Navigate().Refresh();
driver.SwitchTo().Alert().Accept();

When you refresh the page, you may get the alert box (see picture below) and you will have to accept. The second line of code above does this step.


Now, if you want to re-submit the data, search for the WebElement which does the submit and Click again.

No comments: