无法找到使用Appium的iOS原生应用程序的网页视图页面上的元素 [英] Can't find an element on a webview page of an iOS native app using Appium
问题描述
我有几个打开网页查看页面的本地应用程序。我的应用程序运行appium要做到这一点,我需要向下滚动找到用户名和密码字段的Web视图页上的一些自动化的测试。我尝试了所有的建议,我可以在网上找到,而且这是行不通的。任何人都可以帮忙吗?
我在跑:
Appium v1.3.5
的iOS 8.1
I have a native app which opens few web-view pages. I'm running appium on the app to do some automation test on a web-view page that I need to scroll down to find the username and password fields. I tried all the suggestion I can find online, and it doesn't work. Can anyone help? I'm running: Appium v1.3.5 iOS 8.1
下面是我的code:
// switch to webview
Thread.sleep(6000);
final Set<String> contextNames = driver.getContextHandles();
for (final String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains("WEBVIEW")) {
driver.context(contextName);
}
}
Thread.sleep(6000);
WebElement x = driver.findElement(By.cssSelector("Username *"));
assertTrue(x.isDisplayed());
下面是我尝试滚动并输入用户名元素
Here is the element I try to scroll to and enter username
<AppiumAUT>
<UIAApplication name="Demo A" label="Demo A" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0" x="0" y="24.125" width="375" height="642.1875">
<UIAWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/2" x="0" y="0.6875" width="375" height="665.625">
<UIAScrollView name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/2/1" x="29.296875" y="40.53125" width="316.40625" height="548.4375">
<UIAWebView name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/2/1/0" x="29.296875" y="40.53125" width="684.375" height="1170.703125">
<UIAStaticText name="Username *" label="Username *" value="" dom="[object Object]" enabled="true" valid="true" visible="false" hint="" path="/0/2/1/0/15" x="94.921875" y="783.5" width="92.578125" height="22.265625">
</UIAStaticText>
<UIATextField name="" label="" value="" dom="[object Object]" enabled="true" valid="true" visible="false" hint="" path="/0/2/1/0/16" x="94.921875" y="811.625" width="604.6875" height="46.875">
</UIATextField>
下面是错误消息:
org.openqa.selenium.InvalidElementStateException: SyntaxError: DOM Exception 12 (WARNING: The server did not provide any stacktrace information)Command duration or timeout: 22 milliseconds
我曾尝试以下不工作:
I have tried the following and doesn't work:
- 开关首先使用
driver.switchTo()窗口窗口(WEBVIEW_1);
- 使用
driver.findElement(By.id(用户名*))
- 使用
driver.findElement(通过
.xpath(//输入[@名称='用户名*'])); - 使用
driver.findElement(通过.xpath(\"//UIAApplication[1]/UIAWindow[3]/UIAScrollView[1]/UIAWebView[1]/UIAStaticText[14]\"));$c$c>
- switch to the window first using
driver.switchTo().window("WEBVIEW_1");
- use
driver.findElement(By.id("Username *"))
- use
driver.findElement(By .xpath("//input[@name='Username *']"));
- use
driver.findElement(By .xpath("//UIAApplication[1]/UIAWindow[3]/UIAScrollView[1]/UIAWebView[1]/UIAStaticText[14]"));
我也试过先滚动到它:
- 使用刚
scollto:driver.scrollTo(用户名*);
- `((JavascriptExecutor)驱动程序).executeScript(
- 参数[0] .scrollIntoView(真);,driver.findElement(By.name(用户名*)));`
错误信息或者是NoSuchElement或以上的人。
Error message are either NoSuchElement or the one above.
请帮帮忙!谢谢!
推荐答案
我会去driver.findElement(By.xpath(// UIAStaticText [包含(@名称,用户名)));实际上,对于元素位置的所有搜索方法可以在Appium督察进行测试首先,看看他们的工作。
I'd go for driver.findElement(By.xpath("//UIAStaticText[contains(@name,'Username')]")); Actually, all search methods for element location can be tested in Appium Inspector first to see if they work.
这篇关于无法找到使用Appium的iOS原生应用程序的网页视图页面上的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!