Virendra Joshi
Virendra Joshi

Reputation: 479

Issue with finding text after clicking a button in RC

Couldn't access document.body. Is this HTML page fully loaded? This is the error I an getting with selenium RC . I am working on testNG framework and I write my test scripts in java in Eclipse.I use Selenium RC to execute my test scripts. This is the error I am getting after click on save button on an Edit window.Though I have used Thread.sleep("1000") between click on save and next call My Piece of code looks like

            selenium.click(saveButton);     
            Thread.sleep(sleep);      
            while(selenium.isTextPresent("Processing ...")) 
            Thread.sleep(sleep);

I am getting the error on while(selenium.isTextPresent("Processing ...")) line.

Upvotes: 0

Views: 373

Answers (3)

erhun
erhun

Reputation: 3649

Actually i have a similar problem and after some search at forums at selenium user groups decide that the Ajax call cause this, AJAX page loading is taking some time but Selenium is trying to go to next command without waiting the previous call to complete. selenium.waitForPageToLoad(10000) does not wait for AJAX, first i try some speed bumper between the commands, after your Ajax call and just before you check the text. But after read this blog post about selenium tests http://zurmo.org/wiki/selenium i decide to add selenium.waitForCondition() method to wait for jQuery load. I use this structure now:

        selenium.waitForPageToLoad(10000);
        selenium.waitForCondition("typeof selenium.browserbot.getCurrentWindow().jQuery == 'function'", "10000");
        Thread.sleep(1000L);
        Assert.assertTrue("Warning Message", selenium.isTextPresent("elementText"));

Blog post suggest

  1. Write all your tests in the FireFox IDE and focus first on getting it running successfully there.
  2. Do not worry about Chrome/IE, as the first objective is a stable test suite in FireFox. It is more important to have it fully stable on one browser than sort-of working in 3 browsers
  3. Write all your tests to work on FAST speed. In the beginning we thought that because selenium was finicky we had to write everything to run on SLOW speed. This in fact creates problems, so make your test run on FAST speed. We have found only one spot so far that requires temporarily slowing the speed down for several lines. I will mention that in a bit. Anytime you are doing an action that causes the entire page to load you need to follow the following pattern:

Pattern for going directly to a url

  • open – myURL

  • waitForPageToLoad

  • waitForCondition – selenium.browserbot.getCurrentWindow().jQuery.active == 0(I change here to "typeof selenium.browserbot.getCurrentWindow().jQuery == 'function'" this is working for me.)

But i strongly recommend to read the blog post.

Upvotes: 0

Kanishka Choudhury
Kanishka Choudhury

Reputation: 548

you can try out different wait statement. waitForTestPresent, WaitForElementPresent. this way selenium know how much to wait for and what to wait for. also u can use clickAndWait..

Upvotes: 0

Ross Patterson
Ross Patterson

Reputation: 9570

After your selenium.click(saveButton), instead of a Thread.sleep(sleep) that might not be the right length of time, you should selenium.waitForPageToLoad(...).

Upvotes: 1

Related Questions