I have a link on a page, which refreshes this page when clicked.
How can I verify with Selenium-IDE that the page has really been refreshed/reloaded?
I have a link on a page, which refreshes this page when clicked.
How can I verify with Selenium-IDE that the page has really been refreshed/reloaded?
I've solved it by asserting that an element which was originally present on the page, is not present on the page right after refresh, then wait untill the page is fully refreshed, and assert that the element is present again.
UPDATE: Page refresh can also easily be verified if there is some textbox element present. Simply use type command to insert some text into the textbox field, then refresh the page, and the text inside textbox should return to it's original state.
Simple way is to wait until last element on page.
In Selenium-IDE you may use a lot of wait*-commands to do this, for example:
waitForElementPresent [element_xPath]
waitForVisible [element_xPath]
and so on.
If like me you found that checking for the visibility and invisibility of elements can be unreliable, there is an alternative.
If your website uses jQuery, I found that the most reliable method is to check the status of jQuery.active
to determine a page refresh.
For example, In C# I use the following method:
public bool CheckPageHasRefreshed()
{
try
{
// Wait for jQuery to become active (the page is refreshing)
wait.Until(x => (((IJavaScriptExecutor)WebDriver).ExecuteScript("return jQuery.active != 0")));
// Wait for jQuery to become inactive (the page refresh has completed)
wait.Until(x => (((IJavaScriptExecutor)WebDriver).ExecuteScript("return jQuery.active === 0")));
return true;
}
catch (WebDriverTimeoutException)
{
return false;
}
}
This works because jQuery.active will only return 0 when all back-end loading activity on your page has completed. If stuff is still happening behind the scenes, it won't.
What you could assume is - if the element is found, and element.click() has been called, the element has been clicked.
But for good practice - you should catch an exception if the element is not found in the DOM. I.E if it goes into catch block, then you know the page has not been refreshed.
try{
WebElement element = driver.findElement(selector); //The refresh link user clicks
element.click();
clicked = true;
}catch(Exception e){
clicked = false;
throw new ElementNotFoundException();
}