【问题标题】:How to Switch between Native Mobile App to Web Application to verify the elements on it如何在 Native Mobile App 和 Web Application 之间切换以验证其上的元素
【发布时间】:2017-03-05 18:19:43
【问题描述】:
问题:
- 在 Android 设备上,我使用 Appium 自动化工具启动应用程序,这是一个原生应用程序,该应用程序具有指向 Web URL 的外部链接。一旦用户点击它,就会启动 URL
- 现在在这个 URL 上,我需要验证它是否已按预期启动了正确的 URL
到目前为止我做了什么:
- 启动本机应用程序
- 点击应用中的链接
- 外部浏览器启动
- 已检查 URL 的元素
- 现在我的脚本会查找该元素以获取 url 文本,例如 - driver.findelement(by.id(" ")).gettext();
- 当它进入第 5 步时,会看到错误提示找不到元素
feel是什么,web view上找不到元素,需要从mobile view切换到web view吗?
如果有,怎么办?
【问题讨论】:
标签:
java
android
automation
appium
【解决方案1】:
我们开始吧:
MobileElement makeTextLocartor = (MobileElement) wd
.findElementByAndroidUIAutomator("new UiSelector().description(\"<text>\")");
makeTextLocartor.click();
MobileElement TextLocartor = (MobileElement) wd
.findElementByAndroidUIAutomator("new UiSelector().text(\"<text>\")");
makeTextLocartor.click();
wd.findElementById("android:id/button1").click();
WebElement findElementById = wd.findElementById("com.android.chrome:id/url_bar");
String text = findElementById.getText();
System.out.println(text);
以上代码将帮助您获取 chrome 地址框文本。