I have a series of links on a page that take different times to load... I want to capture the amount of time each takes... The problem I am having is that the waitForPageToLoad time if exceeded causes the test to fail and the rest of my links do not get tested... I know I could just skip suspected links in the test or set the time limit way beyond expectation, but I was hoping there was an alternative to the waitForPageToLoad that could be used to trap when a page is loaded in Selenium, so that if a page takes longer than a minute to load it doesn't end the script.
A:
The best way that you can do this is to set the timeout to a number far in the future because 30 seconds is the default timeout for selenium.
setTimout | 300
And then you can do waitForElementPresent
call on an object on the next page if you don't want to do waitForPageToLoad
AutomatedTester
2009-07-29 18:48:23
waitForElementPresent gets me close, but I also need the timeout to end the test for the link if it takes like 5mins and I need it to continue the script and test the rest of the links etc..
2009-07-29 23:36:48
you are always going to have to use setTimeout with a value far in the future then
AutomatedTester
2009-07-30 05:34:48
A:
So it sounds like i might have to go to an export to perl or java to get the functionality i'm looking for then. But, the waitForElementPresent did help a lot. thanks :-)
something like...
for (int second = 0; ; second++) {
if (second >= 300) break;
try {if (selenium.isElementPresent( mylink )) break;}
catch (Exception e) {}
Thread.sleep(1000);
}
if you can export then its always worth it. From Selenium Core/IDE there is a setTimeout call that will set the timeout for that test case to a value and if something appears before that then it will carry on
AutomatedTester
2009-07-31 07:04:52
+1
A:
Here's what I would use:
int second = 0;
while(!selenium.IsElementPresent(mylink))
{
if(second >= 300)
break;
Thread.Sleep(1000);
}
You really don't need\want the try-catch (exception) block since IsElementPresent is not supposed to throw exceptions.
Wesley Wiser
2009-08-20 16:34:59
A:
Wawa's answer worked great for me, I just had to add the increment to the second var.
I also only wanted to wait 5 seconds, so I changed the break criteria.
int second = 0;
while(!selenium.IsElementPresent(mylink))
{
if(second >= 5)
break;
Thread.Sleep(1000);
second++;
}
Captain Obvious
2009-11-18 00:20:29