Selenium中的waitForPageToLoad替代方法 [英] alternative for waitForPageToLoad in Selenium

查看:704
本文介绍了Selenium中的waitForPageToLoad替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个页面上有一系列链接,需要不同的时间来加载...我想捕获每次使用的时间量...我遇到的问题是waitForPageToLoad的时间(如果超出)会导致测试失败,我的其他链接没有被测试...我知道我可以跳过测试中的可疑链接或设置超出预期的时间限制,但我希望有一个替代waitForPageToLoad可以用于在Selenium中加载页面时陷阱,以便如果一个页面花费的时间超过一分钟加载它不会结束脚本。

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.

推荐答案

Wawa的回答对我来说非常棒,我只需要将增量添加到第二个var。

Wawa's answer worked great for me, I just had to add the increment to the second var.

我也只想等5秒钟,所以我更改了休息条件。

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++;
}

这篇关于Selenium中的waitForPageToLoad替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆