vote up 1 vote down
star

Anyone know how to check if page is loading before calling selenium waitForPageToLoad? (to avoid unnecessary exception)

(from Twitter - @marisaseal)

flag

4 Answers

vote up 2 vote down
check

Justin,

Just last week I needed to to this, and came up with the following scheme. Note that I use Perl to drive my Selenium RC tests.

# start from somewhere else from page of interest
$sel->open_ok("/otherpage");
$sel->wait_for_page_to_load_ok($PAGE_DELAY);

$t0 = [gettimeofday];
$sel->click_ok("browser_home");
$sel->wait_for_element_present_ok("link=click_here", 60000);
$elapsed = tv_interval($t0);

# wait for rest of page to load
$sel->wait_for_page_to_load_ok($PAGE_DELAY);

The idea is to time how long it takes to load an element in the page.

1) start from another page that has a link on it to the page of interest

  <a id="browser_home" title="Go to the homepage." href="../pages/Home/">Home</a>

2) we then click on this link, and see how much time it takes for an element to appear. In my case, I am looking for a specific link "click_here" to appear.

Om firefox 3.0 and safari 3.0 under windows XP, it takes about .6 seconds for the link to appear, adn about 2 seconds for the whole page. Internet Explorer 8 gives results that don't agree with the other - it may be that it waits for the whole page to load before the wait_for_element_present is tested.

Corey has come up with a web_profiler that gives details on page loading. I used this scheme until I found his.

Thanks,

Marc Herbert

link|flag
vote up 2 vote down

which exception? An exception should only be thrown when waitForPageToLoad() time's out (page isn't loaded yet).

why would you need to check if it is loaded beforehand? If you clarify further I can probably give you an answer.

also, look at waitForCondition(). It might be more along the lines of what you are looking for.

link|flag
vote up 0 vote down

hmm - I'm far from a selenium expert, but would GetLocation() tell you the correct URL before the page is fully loaded? Seems like it should, but I haven't tried it.

link|flag
vote up 0 vote down

Can you someone tell me how Selenium checks for the page reload? In our app, the page looks like reloaded, however, it just one div is shown. Got some exceptions for that.

link|flag

Your Answer

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.