【问题标题】:How can I click on Text link inside in textview in appium如何在appium的textview中单击文本链接
【发布时间】:2019-02-14 19:21:34
【问题描述】:

如何在 appium 的 textview 中点击 Text 链接

例如。我有一个字符串但没有帐户? Register

只有注册有链接,其他文本被禁用,当我点击注册时,它导航到注册屏幕。

但我无法点击注册。

参考图片

【问题讨论】:

  • 你能从这里尝试一次答案吗:stackoverflow.com/questions/36497486/…
  • driver.findElement(By.Xpath("//*[contains(text(), 'REGISTER')]").click();
  • 不工作@AmitJain
  • 不工作@NarendraR
  • @rusito 显式屏幕坐标很好,但我无法在其他手机上运行相同的测试用例。

标签: java automated-tests appium android-uiautomator appium-android


【解决方案1】:
WebElement element = driver.findElement(By.id("element id here"));
Point point = element.getLocation();

//you can change follwing point based on your link location
int x = point.x +1;  
int y = point.y + element.getSize().getHeight() - 1;

new TouchAction(driver).tap(x, y).perform();

我找到了这个解决方案here in appium discussion

【讨论】:

  • 尝试使用 x=point.x+20 改变 x 和 y 的值;或尝试使用 uiAutomatorViewer 进行检查以了解您的元素边界并使用 x 和 y 与该元素的相对值。
  • 元素边界坐标很好,但我不能在其他手机上运行相同的测试用例
  • 该代码可以在您的设备上运行吗?如果这些代码在您的设备上运行,您可以在小屏幕设备和大终端设备上检查它并编写通用代码以支持所有设备。
【解决方案2】:

我通常在我的测试中尽量避免使用 XPATH,因此为了通过文本搜索元素,我正在做这样的事情,这将返回一个 By 元素以用于 webdriver 交互。

public static By byText(final String text)
{
    switch (Configuration.getInstance().getPlatform())
    {
        case ANDROID:
            // This requires a UiAutomator2 test driver:
            return MobileBy.AndroidUIAutomator("new UiSelector().text(\"" + text + "\")");
        case IOS:
        default:
            throw new RuntimeException("not implemented");
    }
}

不幸的是我现在还不知道iOS的等价物,但它应该也有可能;)

【讨论】:

    【解决方案3】:

    使用这个简单的代码

    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", element);
    

    【讨论】:

      猜你喜欢
      • 2019-01-29
      • 2011-12-05
      • 1970-01-01
      • 2016-07-11
      • 1970-01-01
      • 2017-08-18
      • 1970-01-01
      • 2021-04-11
      • 2011-03-20
      相关资源
      最近更新 更多