我有一个示例应用程序可以在 WebView 中打开谷歌搜索页面。我想点击搜索按钮。但是得到找不到元素的错误。是否可以自动化在 webview 中加载的网页?如果是这样,我的代码中缺少什么?请建议..
应用代码(相关):
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
测试代码:
Button myView = solo.getView(Button.class, 0);
solo.waitForView(myView, 20, false);
solo.clickOnView(myView);
WebView view = solo.getView(WebView.class, 0);
solo.waitForView(view, 100000, false);
solo.clickOnWebElement(By.id("gbqfb"));
错误在 solo.clickOnWebElement
错误:
junit.framework.AssertionFailedError: WebElement with id: 'gbqfb' is not found!
at com.jayway.android.robotium.solo.Clicker.clickOnWebElement(Clicker.java:343)
at com.jayway.android.robotium.solo.Solo.clickOnWebElement(Solo.java:890)
at com.calculator.test.TestApk.testSpinnerlist(TestApk.java:51)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
UI Automator Viewer 截取的屏幕截图将整个页面显示为 (package -com.android.browser, class - android.webkit.WebView) 但未识别页面上的其他对象。
环境——Android4.3、Robotium4.3、模拟器、Windows7 x32
PS-On Emulator,搜索按钮(id=gbqfb) 默认出现。还尝试在搜索文本字段中键入内容,但也因类似原因而失败。 solo.typeTextInWebElement(By.id("gbqfq"), "testing")
最佳答案
Google 更改输入字段的 ID。尝试寻找 By.name("q")
而不是
关于android - 使用 Robotium 4.3 进行网页测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18942229/