|
本帖最后由 donkey0702 于 2015-6-9 18:02 编辑
代码如下:
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.FindBy;
public class ClickButton {
WebDriver driver;
@Before
public void setUp() throws InterruptedException {
System.setProperty("webdriver.ie.driver", "G:\\Selenium\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.get("http://www.baidu.com");
Thread.sleep(2000);
}
@Test
public void login(){
WebElement username;
username=driver.findElement(By.xpath("//Input[@id='kw']"));
Assert.assertEquals(username.getSize(),1);
username.sendKeys("abc");
}
@After
public void tearDown(){
driver.quit();
}
public static void main(String[] args) throws InterruptedException {
ClickButton a=new ClickButton();
// a.tearDown();
a.setUp();
a.login();
// a.tearDown();
}
}
会报错, 但ff就可以定位到,请高手指点怎么修正?谢谢!
Listening on port 38152
Jun 09, 2015 5:53:12 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed
Jun 09, 2015 5:53:12 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information) |
|