2017-10-05 28 views
0

我在为Android做Appium,并且我已经知道如何使用scrollIntoView()查找元素。如何使用MobileElement在Appium Android中查找它的兄弟姐妹

我的表是这样的:

(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 

正如我上面提到的,我可以找到(0)的TextView文本“汤姆”和ID。但是,我想要的是找到(1)TextView并单击它。有什么办法可以做到吗?

我在寻找类似:

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

回答

0

你可以试试这个使用XPath。下面是一个例子

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

您可能希望上面的参数

+0

它实际上工作,但我必须使用驱动程序,而不是汤姆。 –

0

文本这是我最后做的。

由于scrollIntoView()可以向下滚动,直到汤姆和目标都显示在屏幕上,我终于做到以下几点:

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

我使用的驱动程序,而不是汤姆找到的元素。