|
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时,长时间没有反应 |
|