【问题标题】:Can't find an element on a webview page of an iOS native app using Appium在使用 Appium 的 iOS 本机应用程序的网页视图页面上找不到元素
【发布时间】:2015-05-06 01:49:49
【问题描述】:

我有一个本机应用程序,它打开了几个网页视图页面。我在应用程序上运行 appium 以在需要向下滚动以查找用户名和密码字段的 web 视图页面上进行一些自动化测试。我尝试了所有可以在网上找到的建议,但它不起作用。任何人都可以帮忙吗? 我在跑: Appium v​​1.3.5 iOS 8.1

这是我的代码:

// 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());

这是我尝试滚动到的元素并输入用户名

     <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

我尝试了以下方法,但不起作用:

  1. 首先使用driver.switchTo().window("WEBVIEW_1");切换到窗口
  2. 使用driver.findElement(By.id("Username *"))
  3. 使用driver.findElement(By .xpath("//input[@name='Username *']"));
  4. 使用driver.findElement(By .xpath("//UIAApplication[1]/UIAWindow[3]/UIAScrollView[1]/UIAWebView[1]/UIAStaticText[14]"));

我也尝试先滚动到它:

  1. 只使用scollto: driver.scrollTo("Username *");
  2. `((JavascriptExecutor) 驱动程序).executeScript(
    • "arguments[0].scrollIntoView(true);", driver.findElement(By.name("Username *")));`

错误消息是 NoSuchElement 或上述错误消息。

请帮忙!谢谢!

【问题讨论】:

    标签: selenium-webdriver webdriver automated-tests appium ios-ui-automation


    【解决方案1】:

    如果您测试网络应用程序,则必须使用网页定位器。在此处查看我的答案(已更正:)):Unable to find an element in Browser of the Android emulator using Appium and C#

    【讨论】:

      【解决方案2】:

      我会选择 driver.findElement(By.xpath("//UIAStaticText[contains(@name,'Username')]"));其实,所有元素位置的搜索方法都可以先在 Appium Inspector 中进行测试,看看是否有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-31
        • 1970-01-01
        • 2021-02-13
        • 1970-01-01
        相关资源
        最近更新 更多