【转载】selenium等待页面跳转

上一篇 / 下一篇  2011-09-19 18:12:39 / 个人分类:Selenium

selenium,之前用过PAMIE, QTP。只觉得selenium真的有点慢。并且等待页面跳转只能够Thead.sleep().或者waitForPageLoad("3000"). 自己估算页面跳转的时间。 可是这样估算有点浪费等待时间,无法估算得刚刚好。如果可以判断下一个页面出现某个元素(常常是将要操作的元素)出现,则进行下一步的动作这样就能节省页面等待的时间了。但是直接用selenium RC,不用selenium ide 没有那些waitForElementPresent的方法。

网上找了一个wait的方法。

Wait wait = new Wait() {
public boolean until() {
return selenium.isElementPresent(locator);
// or selenium.isTextPresent(pattern);
}
};
wait.wait("", timeoutInMilliseconds);

 

可是用了一下,没学会怎么用。。。

 

自己写了一个。

 

public void waitForElementPresent(String locator, Selenium browser) throws InterruptedException{

int i = 0;

while(true){

if(browser.isElementPresent(locator)) break;

else if (browser.isTextPresent(locator)) break;

else{ 

Thread.sleep(1000); //等待一秒

if(i++>100) break;

}

}

}

 

调用的时候: verifying.waitForElementPresent("Search Screens",browser);


TAG:

 

评分:0

我来说两句

Open Toolbar