51Testing软件测试论坛
标题:
webdriver 不能抛出NoSuchElementException异常
[打印本页]
作者:
dpdpdp
时间:
2012-12-21 12:02
标题:
webdriver 不能抛出NoSuchElementException异常
findElement(By) 在firefox下对象不存在时,不能抛出NoSuchElementException异常,chrome 和ie 下都正常,有人遇到过么
package test;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class google {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.firefox.bin","D:/Program Files/Mozilla Firefox/firefox.exe");
System.setProperty("webdriver.chrome.driver","D:/Python27/Scripts/chromedriver.exe");
WebDriver driver = new InternetExplorerDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("http://www.baidu.com/");
boolean resultsDiv = driver.findElement(By.id("kw1")).isDisplayed();
System.out.print(resultsDiv);
WebElement query = driver.findElement(By.id("kw"));
query.sendKeys("111");
driver.quit();
}
}
复制代码
当
WebDriver driver = new InternetExplorerDriver();
复制代码
使用ie chrome时
boolean resultsDiv = driver.findElement(By.id("kw1")).isDisplayed();
复制代码
都能得到NoSuchElementException异常
但使用firefox时,长时间没有反应
作者:
六月天
时间:
2012-12-21 12:35
帮你试了一下,有NoSuchElementException异常,没问题
作者:
dpdpdp
时间:
2012-12-21 12:56
谢谢楼上,我换台机器试试,难道是firefox的问题?
作者:
dpdpdp
时间:
2012-12-24 09:48
selenium2.25,升级到2.27可以工作正常了
作者:
shijin880921
时间:
2012-12-26 10:10
我最近也在研究webdriver,创建了这个群238488255,里面还是有几个高手的,大伙以后一起学习吧。
作者:
遇上鱼子
时间:
2013-1-23 17:42
其实这里有问题:5, TimeUnit.SECONDS 等待超时时间太短了吧!
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2