简体   繁体   English

在appium中查找元素

[英]Find element in appium

How do I find an element in a linear layout which have a specific index, as obtain in the image I have this element android.widget.EditText , which has index 3. When I try to find it using the search parameter: 如何在线性布局中查找具有特定索引的元素,如在图像中获取的,我具有此元素android.widget.EditText ,该元素的索引为3。当我尝试使用搜索参数查找它时:
driver.FindElement(By.XPath("//android.widget.EditText[@index='3']")).SendKeys("123");
and I tried this as well 我也尝试过
driver.FindElementByXPath("//*[@class='android.widget.EditText' and @index='3']").SendKeys("123");

I get this exception {"An element could not be located on the page using the given search parameters."} 我收到此异常{"An element could not be located on the page using the given search parameters."}

How can i select this element? 如何选择此元素?

Since index is involved , i would suggest u to put the element identifier in a list and and get index and click. 由于涉及索引,我建议您将元素标识符放入列表中,然后获取索引并单击。 Try the below code 试试下面的代码

List<WebElement> list= driver.findElements(By.XPath("identifier"));
System.out.println("size of List= " + list.size());
        list.get(3).click();

What you have is driver.FindElement(By.XPath("//android.widget.EditText[@index='3']")).SendKeys("123"); 你所拥有的是driver.FindElement(By.XPath("//android.widget.EditText[@index='3']")).SendKeys("123"); which is the syntax for searching for an xpath by attribute where @attribute is the attribute. 这是按属性搜索xpath的语法,其中@attribute是属性。 For index, however, it is simpler. 但是,对于索引,它更简单。 Just do driver.FindElement(By.XPath("//android.widget.EditText[3]")).SendKeys("123"); 只需要做driver.FindElement(By.XPath("//android.widget.EditText[3]")).SendKeys("123");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM