【问题标题】:How to Click on a Button using content-desc如何使用 content-desc 点击按钮
【发布时间】:2015-01-09 07:04:48
【问题描述】:

我是使用 Appium 在 C# 中进行测试的新手。我能够设置一切并运行测试。 我使用 UiAutomatorViewer 来访问一些按钮,现在我需要单击一个按钮,但我刚刚得到了 Cont-desc。 哪个 FindElement(ByAndroidUIAutomator."") 链接到 cont-desc?我什么都试过了,但总是出错。我已经尝试使用 TouchAction 或 mouse.Click() 来单击此按钮;没有任何效果... 任何帮助都会很好。

提前致谢:)

【问题讨论】:

    标签: c# android testing appium


    【解决方案1】:

    使用 content-desc 访问元素的简单方法是使用

    driver.findElementByName("Login").click();
    

    重要提示:注意空格,我在查找元素时遇到问题,因为 content-desc 中的文本在文本末尾有一个空格...

    【讨论】:

      【解决方案2】:

      通过XPATH找到webelement,然后点击如下:

      driver.FindElement(By.XPath("//android.widget.Button[@content-desc='Login']")).Click();
      

      【讨论】:

      • 有人可以帮帮我吗,我阅读了有关 XPath 的教程并尝试了所有方法。它总是抛出一个异常:InvalidOperationException..
      【解决方案3】:

      这对我有用。

      driver.findElementByAndroidUIAutomator("UiSelector().description(\"Login\")").click();

      参考: http://developer.android.com/tools/help/uiautomator/UiSelector.html#childSelector(com.android.uiautomator.core.UiSelector)

      【讨论】:

        【解决方案4】:

        试试这个:

        driver.FindElement(By.Name('Login')).Click();

        这是访问内容描述的方式。它基本上是视图的名称。

        【讨论】:

          猜你喜欢
          • 2020-03-26
          • 2020-02-19
          • 2016-10-29
          • 2021-10-07
          • 2019-09-21
          • 2017-08-08
          • 1970-01-01
          • 1970-01-01
          • 2017-04-06
          相关资源
          最近更新 更多