Appium 请教下 appium 如何访问 webView 内的元素,先谢了

库仑 · 2014年10月20日 · 最后由 库仑 回复于 2014年10月22日 · 3471 次阅读

step5.click();
Thread.sleep(50000);

// this is important part.
//System.out.println(driver.getCurrentUrl());
driver.context("WEBVIEW");
// driver.switchTo().window("WEBVIEW");
System.out.println(driver.getCurrentUrl());
Thread.sleep(20000);
driver.findElementById("login_email"); <----------代码到这里出错

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.26 seconds
Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc', time: '2014-06-03 10:52:47'
System info: host: 'PC-20140519QFMN', ip: '172.20.1.58', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_05'
Driver info: io.appium.java_client.AppiumDriver
Capabilities [{appPackage=com.gamelala.android.trivialdrivesample, warnings={}, databaseEnabled=false, deviceName=Android Emulator, platform=LINUX, appActivity=.DemoActivity, desired={appPackage=com.gamelala.android.trivialdrivesample, appActivity=.DemoActivity, platformVersion=4.4.2, browserName=, platformName=Android, deviceName=Android Emulator}, platformVersion=4.4.2, webStorageEnabled=false, browserName=, takesScreenshot=true, javascriptEnabled=true, platformName=Android}]
Session ID: e374d3f2-da5a-4b4a-b815-7bf560d920ff
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:95)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByCssSelector(RemoteWebDriver.java:441)
at org.openqa.selenium.By$ByCssSelector.findElement(By.java:425)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at Gamelala_01.GL_PAY.MainProcess.a_Paypal_Ts(MainProcess.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
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)

共收到 6 条回复 时间 点赞

确定页面已经出现了"login_email"的元素?
以前碰过,如果页面没有出现要点击的元素,报错和妳的是一样的
An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)

不过妳睡的时间够长的,20 秒。

你在用这句话(driver.context("WEBVIEW");)的时候,先把当前的 context 都打印出来看一下

测试了代码:
Set contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextName);
}
结果打印出:
WEBVIEW_com.test.android.trivialdrivesample ,请教下这个算是 webview 吗
这样的话,driver.context("WEBVIEW");中这个 WEBVIEW 应该怎么写

#3 楼 @akira0002 代码请用代码块,发帖的时候看右边的提示啊。

移动端可能是另一套页面,属性之类不一定和 PC 端一样。
Chrome 开发者工具可以模拟移动设备,你搜下 “chrome 设备模拟器” 之类的关键字看看

你这个是 server 端错误,应该贴上 appium 日志。


请问这是什么错误啊
没有任何提示的

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册