!!

Welcome to Selenium Webdriver Forum

As a web user you can read and search through forum content. Once you have registered and signed you can post topics, post replies, set up watch lists, modify forum settings, and use private messaging.

Author Topic: WebDriver not waiting for page to load after a button click  (Read 9594 times)

Phil

  • Web User
WebDriver not waiting for page to load after a button click
« on: April 11, 2012, 03:46:16 PM »
Hi all,
 WebDriver doesn't seem to be waiting for any pages to reload after it
 clicks a button.  When dealing with links it seems to be working fine,
 but for buttons it moves on to the next component straight away and
 obviously throws an error when that component doesn't exist yet.
 Here's the code I'm using to interact with buttons;
 
private void invokeButton(IWebDriver driver, string value)
         {
             string input = "//input[contains(@value, '" + value + "')
 and (@type='button' or @type='submit')]";
 
            driver.FindElement(By.XPath(input)).Click();
         }
 
It is clickign the button ok, just not waiting for the page reload
 afterwords.  Before, I was using the selenium.WaitForPageToLoad()
 function but as far as I know this doesn't work when using
 WebDriverBackedSelenium.  Any help is greatly appreciated.
 
Phil

Tan

  • Web User
Re: WebDriver not waiting for page to load after a button click
« Reply #1 on: April 11, 2012, 03:46:31 PM »
Hi Phil
 By default, WebDriver should wait for the full page reload before
 proceeding. It, however, might not be able to wait for XHR (AJAX)
 requests.
 
Could you use FireBug > Net to manually inspect if there is any XHR
 requests being send as part of the button click? If possible, could
 you also include the minimal HTML/JS here in this post
 
Cheers,
 Tan
 
On Jun 6, 7:26 pm, Phil <owe...@hotmail.co.uk> wrote:
 

- Show quoted text -

Phil

  • Web User
Re: WebDriver not waiting for page to load after a button click
« Reply #2 on: April 11, 2012, 03:46:42 PM »
Hey Tan,
 I switched to the NET > XHR tab and there doesn't seem to be any AJAX
 requests, HTML for the button is listed below;
 
<input type="submit" style="margin-bottom: 20px; margin-left: 20px;"
 onclick="javascript:WebForm_DoPostBackWithOptions(new
 WebForm_PostBackOptions("ctl00$SPWebPartManager1$g_45d3cf2e_d74f_4e93_95b5_8f6c0f935d44$ctl00$map1$ctl04$ctl12",
 "", true, "", "", false, false))"
 value="Next"
 name="ctl00$SPWebPartManager1$g_45d3cf2e_d74f_4e93_95b5_8f6c0f935d44$ctl00$map1$ctl04$ctl12">
 
Thanks
 Phil
 
On Jun 6, 1:34 pm, Tan <tanle...@gmail.com> wrote:
 

- Show quoted text -

Selenium Webdriver

Re: WebDriver not waiting for page to load after a button click
« Reply #2 on: April 11, 2012, 03:46:42 PM »

Simon Stewart

  • Web User
Re: WebDriver not waiting for page to load after a button click
« Reply #3 on: April 11, 2012, 03:47:16 PM »
If you're on Windows then the keyboard and mouse emulation is done at
 the OS, not the browser, level. That means that it's hard for
 webdriver to know whether or not a page load is expected. The
 recommended way of dealing with this is to have the next line use a
 wait, either by using the WebDriverWait class, or by using the
 implicit waits. My preference is to make waits clear and obvious.
 Regards,
 
Simon
 

- Show quoted text -

Simon Stewart

  • Web User
Re: WebDriver not waiting for page to load after a button click
« Reply #4 on: April 11, 2012, 03:47:40 PM »
Not without the page notifying you. If I'm really concerned about
 that, I wait for an element in the footer of the page, and then check
 to see whether my JS libraries have intialized themselves.
 Simon
 

- Show quoted text -

Phil

  • Web User
Re: WebDriver not waiting for page to load after a button click
« Reply #5 on: April 11, 2012, 03:47:52 PM »
I'm not sure how Firebug finds these XHR requests but more than a few
 showed up when sumbitting a couple of forms.  Does this mean then that
 there's no way for WebDriverBackedSelenium to know if a page ahd
 loaded?  I've got a rough re-try clause that doesn't interact with a
 component if selenium.isElementPresent is false, and it tries this 3
 times before giving up, if I'm understanding it right I'd have to
 extend this to say 10 or 15 re-tries to cover page loads and this
 seems pretty sloppy.  Is there really no way to get the old
 selenium.WaitForPageToLoad() to work?
 Phil
 
On Jun 6, 1:55 pm, Phil <owe...@hotmail.co.uk> wrote:
 

- Show quoted text -

Phil

  • Web User
Re: WebDriver not waiting for page to load after a button click
« Reply #6 on: April 11, 2012, 03:48:39 PM »
Thanks Simon, I'll some other method to verify a page has loaded. =)
 Phil
 
On Jun 8, 2:11 pm, Simon Stewart <simon.m.stew...@gmail.com> wrote:
 

- Show quoted text -

Shannon Null Code

  • Web User
Re: WebDriver not waiting for page to load after a button click
« Reply #7 on: April 11, 2012, 03:49:05 PM »
My solution for these cases was to create my own waitForPageLoaded
 method that checked the browser readystate
 public void waitForPageLoaded() {
 
                ExpectedCondition<Boolean> expectation = new
 ExpectedCondition<Boolean>() {
                   public Boolean apply(WebDriver driver) {
                     return ((JavascriptExecutor)driver).executeScript("return
 document.readyState").equals("complete");
                   }
                 };
 
                Wait<WebDriver> wait = new WebDriverWait(INSTANCE_OF_YOUR_WEBDRIVER,
 30);
                 try {
                         wait.until(expectation);
                 } catch(Throwable error) {
                         fail("Timeout waiting for Page Load Request to complete.");
                 }
         }
 
On Jun 8, 9:11 am, Simon Stewart <simon.m.stew...@gmail.com> wrote:
 

- Show quoted text -

Simon Stewart

  • Web User
Re: WebDriver not waiting for page to load after a button click
« Reply #8 on: April 11, 2012, 03:49:19 PM »
You've still got a race condition to deal with: the one where the load
 hasn't even started yet when you do your check.
 One way of dealing with this problem is to add a unique key to the
 "window" global before performing the action that loads the page. A
 page reload will cause this variable to be deleted, so it's an easy
 thing to check for.
 
Regards,
 
Simon
 
On Wed, Jun 29, 2011 at 12:42 AM, Shannon Null Code <genecy...@gmail.com> wrote:
 

- Show quoted text -

Luke Inman-Semerau

  • Web User
Re: WebDriver not waiting for page to load after a button click
« Reply #9 on: April 11, 2012, 03:50:07 PM »
That's the wrong jar... you only use that to launch the (remote) server,
 when coding you need to include the selenium-java.jar
 http://selenium.googlecode.com/files/selenium-java-2.0rc2.zip
 
On Mon, Jun 6, 2011 at 8:53 AM, Nitin Purswani <nitinpursw...@gmail.com>wrote:
 

- Show quoted text -

Simon Stewart

  • Web User
Re: WebDriver not waiting for page to load after a button click
« Reply #10 on: April 11, 2012, 03:50:22 PM »
The standalone jar should have everything you need. It is, indeed, an
 oversight that it doesn't.
 Simon
 
On Mon, Jun 6, 2011 at 7:27 PM, Luke Inman-Semerau
 

- Show quoted text -

 

Related Topics

  Subject / Started by Replies Last post
2 Replies
1248 Views
Last post February 23, 2012, 07:26:32 PM
by David Byron
1 Replies
1462 Views
Last post March 27, 2012, 05:08:23 PM
by Tarun Bhadauria
3 Replies
1322 Views
Last post March 27, 2012, 09:04:23 PM
by Darrell DeBoer
2 Replies
1634 Views
Last post April 04, 2012, 08:03:39 PM
by QA_manager
2 Replies
628 Views
Last post April 12, 2012, 06:41:34 PM
by David Byron
2 Replies
1070 Views
Last post April 12, 2012, 07:32:34 PM
by David Byron
4 Replies
699 Views
Last post July 24, 2012, 09:54:41 PM
by Sunilgcc