How to know if a page has been reloaded after some ajax refresh

239 views
Skip to first unread message

Vincent Massol

unread,
Jun 8, 2011, 11:37:51 AM6/8/11
to webd...@googlegroups.com
Hi there,

I have a page that has javascript that reloads the page. I'm using the PageObject strategy and I'd like to know if there's a generic way for my method in the PageObject to wait till the page has finished reloading.

If that's not possible then I need that the code using the PageObject method to do his own wait. I'd prefer it if it could be done generically.

Thanks

Binken

unread,
Jun 8, 2011, 10:02:21 PM6/8/11
to webd...@googlegroups.com
You can do some waiter until element appears in the new page

Vincent Massol

unread,
Jun 9, 2011, 2:10:20 AM6/9/11
to webd...@googlegroups.com
Hi Binken,

It's not possible to do this generically in the PageObject since the page that refreshes is the *same* as the previous page so the wait will immediately return before the new page has loaded.

Thanks

Binken

unread,
Jun 9, 2011, 4:02:36 AM6/9/11
to webd...@googlegroups.com

Nilesh

unread,
Jun 9, 2011, 1:25:37 PM6/9/11
to webdriver
If your application is AJAX heavy and if you are using PageFactory
along with PageObjects then you can use AjaxElementLocatorFactory[1].
This is useful for finding elements in general.

AjaxElementLocatorFactory factory = new
AjaxElementLocatorFactory(driver, 15/*TimeOut*/);

As of the Page to load, in my case, I am using jQuery.Active property
to make sure if the AJAX requests are complete or not. I have
something like below in my method. I am able to use jQuery object
because our application uses jQuery. If your application does not use
jQuery then perhaps you will have to find some other ways like
ImplicitlyWait or WebDriverWait etc

while(AJAXCompletesUntilCertainTimeOut){
if(((JavascriptExecutor)driver).executeScript("return
jQuery.active;").toString().equals("0")){
return true;
}
}
[1]http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/
selenium/support/pagefactory/AjaxElementLocatorFactory.html

Nilesh

unread,
Jun 9, 2011, 1:29:51 PM6/9/11
to webdriver
I meant while AJAX not complete until certain time out in the while
loop. You will have to implement that logic using some kind of timers.

while(AJAXNOTCompleteUntilCertainTimeOut){

Rostislav Matl

unread,
Jun 9, 2011, 6:18:31 PM6/9/11
to webdriver
Use either com.thoughtworks.selenium.Wait or WebDriverWait and
ExpectedCondition from
org.openqa.selenium.support.ui - combine it with JavascriptExecutor.
If you add some variable
(some counter e.g.) to AJAX handler you can easily check its value in
the until() method of
mentioned classes.

Vincent Massol

unread,
Jun 14, 2011, 4:14:47 AM6/14/11
to webd...@googlegroups.com
Hi Binken,

The link you gave is a gmail link which doesn't work for me obviously ;)

Thanks!

Vincent Massol

unread,
Jun 14, 2011, 4:16:57 AM6/14/11
to webd...@googlegroups.com
Hi,

I'm already using AjaxElementLocatorFactory. jQuery.Active seem error prone since checking it will return that there's no active queries for the current page if it gets executed before the page has been refreshed. Also I made a mistake in the title of the post, it's not an Ajax refresh but simply a JS refresh.

Thanks anyway
Reply all
Reply to author
Forward
0 new messages