我最近更新了Selenium 2.24.1以使Firefox 13能够正常工作。随着这个更新,你现在可以运行一个类似chromedriver.exe的可执行文件来将事件分派到IE。然而,我一直没有成功地让测试在IE中运行。为了让它在chrome中运行,我显然还要设置webdriver.chrome.driver位,但是相同代码在它和Firefox中运行良好。
以下是我的源代码:
public class GoogleTest {
@Test
public void test() throws Exception {
System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
final WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com");
driver.findElement(By.name("q")).sendKeys("test");
driver.findElement(By.name("q")).submit();
driver.quit();
}
然而,当我执行这个测试时,遇到了以下堆栈跟踪:
org.openqa.selenium.NoSuchElementException: Unable to find element with name == q (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 395 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 15:28:49'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_01'
Driver info: driver.version: RemoteWebDriver
Session ID: e20f8370-00ed-4bf6-a4fa-a0c09c2b6d8c
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:472)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:303)
at org.openqa.selenium.By$ByName.findElement(By.java:291)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:234)