1

我正在为 Android 做 Appium,我已经知道如何使用 scrollIntoView() 来查找元素。

我的表是这样的:

(2)TableLayout
    (0)TableRow
        (0)LinearLayout
        (1)LinearLayout
            (0)TextView:Tom
            (1)TextView:OPEN
            (2)TextView:OPEN
    (1)TableRow
        (0)LinearLayout
        (1)LinearLayout
            (0)TextView:Jack
            (1)TextView:OPEN
            (2)TextView:OPEN

如上所述,我可以使用文本“Tom”和 id 定位 (0)TextView。但是,我想要的是找到 (1)TextView 并单击它。有没有办法做到这一点?

我正在寻找类似的东西:

MobileElement tom = the (0)TextView I located;
MobileElement target = tom.findElement(__);
target.click();
4

2 回答 2

1

这就是我最终要做的。

由于 scrollIntoView() 可以向下滚动直到 tom 和 target 在屏幕上都可见,我最终执行以下操作:

MobileElement tom = scrollToElement(table, name_id, "Tom"); // scrollIntoView()
MobileElement target = driver.findElementByXPath("//*[@text='Tom']/following-sibling::android.widget.TextView[1]");

我使用驱动程序而不是汤姆来查找元素。

于 2017-10-10T17:13:29.957 回答
0

您可以使用 xpath 尝试此操作。下面是一个例子

//*[@text='Tom']/following-sibling::[1 or 2]

您可能想要参数化上面的文本

于 2017-10-07T18:52:26.370 回答