How to wait for all AJAX call to complete for page load

987 views
Skip to first unread message

Santosh Vishwakarma

unread,
Aug 21, 2013, 12:47:41 AM8/21/13
to seleniu...@googlegroups.com
I am working on a application which is developed in MVC 3.0 architecture. When page loads it makes multiple AJAX calls to load multiple objects on page.

My problem is when I want to verify a object, driver find it but when go for click on element or perform any operation on element application triggers other AJAX call for few more element, which makes my found element unable to interact.

How should I put condition to wait till all the elements on page is loaded and process is completed?

robbiewinston

unread,
Aug 21, 2013, 5:13:26 AM8/21/13
to seleniu...@googlegroups.com
Look at the WebDriverWait class.  This will allow you to create your expected condition (e.g. wait until element appears on screen)

There are static methods provided on the ExpectedConditions class but you can also handcraft if your scenario is more complex

David Lai

unread,
Sep 6, 2013, 6:51:55 PM9/6/13
to seleniu...@googlegroups.com, santosh.v...@gmail.com
If you know how to access the JavaScript variable associated with the ajax request, a cool trick you can do is attach a Promise to the ajax call so it'll do a call back when the ajax request succeeds or fails.  This is a good way of avoiding long wait on elements and be able to fail the test as soon as the ajax request errors out or continue if it succeeds.

Ashish Juyal

unread,
Sep 7, 2013, 5:49:24 AM9/7/13
to seleniu...@googlegroups.com
Hi David,
              My idea will be to go for FluentWait,wait for the element to appear.

Regards
Ashish Juyal

Arup Rakshit

unread,
Sep 7, 2013, 1:17:34 PM9/7/13
to seleniu...@googlegroups.com
Could you please share a simple code snippet based on your suggestion ?
> --
> You received this message because you are subscribed to the Google Groups
> "Selenium Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to selenium-user...@googlegroups.com.
> To post to this group, send email to seleniu...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/selenium-users/f42a1484-80cd-4a73-a9e7-6c1c5f8d8bc6%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>


--
*---------------------------------------------------------------*
*Warm Regards,*

*Arup Rakshit*
*Software Engineer*

*Email:* arupr...@rocketmail.com
tuk...@gmail.com
<arupr...@rocketmail.com>

Ashish Juyal

unread,
Sep 10, 2013, 2:45:02 AM9/10/13
to seleniu...@googlegroups.com
Hi Arup
            check for the code below .Keep it under try catch
FluentWait<WebDriver> fluent = new FluentWait<WebDriver>(Driver.driver);
fluent.ignoring(Throwable.class, StaleElementReferenceException.class);
fluent.withTimeout(10, TimeUnit.SECONDS);
fluent.pollingEvery(2, TimeUnit.SECONDS);
fluent.until(ExpectedConditions.visibilityOf(element));

Regards
Ashish Juyal
Reply all
Reply to author
Forward
0 new messages