0

我最近开始使用 -> RemoteWebDriver+AndroidDriver 。我从一个基本示例开始,如下所示:

 stmt1:WebDriver driver=new AndroidDriver();
 stmt2:driver.get("http://www.google.com");
 stmt3:WebElement element = driver.findElement(By.name("q"));
 stmt4:element.sendKeys("Cheese!");

'stmt1','stmt2' 在模拟器上成功打开 google.com。问题是“stmt3”和“stmt4”不起作用。模拟器关闭 webdriver 并在 eclipse 中生成以下异常:

org.openqa.selenium.WebDriverException: Error communicating with the remote browser. It may have died.
Build info: version: '2.12.0', revision: '14666', time: '2011-11-10 18:36:18'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_33'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:412)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:205)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:254)
    at org.openqa.selenium.By$ByName.findElement(By.java:286)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:197)
    at androidpackage.Androidclass$1.apply(Androidclass.java:24)
    at androidpackage.Androidclass$1.apply(Androidclass.java:1)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:189)
    at androidpackage.Androidclass.testAndroid(Androidclass.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at junit.framework.TestCase.runTest(TestCase.java:168)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.apache.http.NoHttpResponseException: The target server failed to respond
    at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:101)
    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:252)
    at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:281)
    at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:247)
    at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:219)
    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:298)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:391)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:370)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:398)
    ... 27 more
4

2 回答 2

0

从堆栈跟踪来看,您的硒版本似乎是 2.12.0。当前版本是2.25.0。可能使用 latest 可以解决问题。

于 2012-07-16T02:39:09.463 回答
0

问题是我使用了 android 2.3.3(Gingerbread 上的错误可能导致 WebDriver 崩溃)。在升级到 android 4.0.3 代码运行良好。

于 2012-07-17T14:32:44.750 回答