Android 如何使用appium在移动应用程序中查找xpath

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23799488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:29:00  来源:igfitidea点击:

How to find xpath in mobile app using appium

androidxpathselenium-webdriverappium

提问by Kaivalya

I tried using Find element by id but it is not inserting required data. Then I used Find element by xpath //android.widget.ScrollView[0]/android.widget.RelativeLayout[0]/android.widget.TextView[0]/ndroid.widget.TextView[1]/android.widget.EditText[2]")).sendKeys("[email protected]");

我尝试通过 id 使用 Find element,但它没有插入所需的数据。然后我用 xpath 查找元素//android.widget.ScrollView[0]/android.widget.RelativeLayout[0]/android.widget.TextView[0]/ndroid.widget.TextView[1]/android.widget.EditText[2]")).sendKeys("[email protected]");

but still it is not working.enter image description here

但它仍然不起作用。在此处输入图片说明

回答by Abhishek Swain

Please use this Xpath , I hope this solves your problem:

请使用这个 Xpath ,我希望这能解决你的问题:

By.xpath("//android.widget.EditText[@text='Email ID']")

回答by user2220762

A better way of doing this is as follows -

这样做的更好方法如下 -

driver.findElement(By.xpath("//EditText[contains(@text,'Edit ID')]"));

回答by Sarika

Find xpath of mobile app using contains

使用 contains 查找移动应用程序的 xpath

driver.findElement(By.xpath("//android.widget.TextView[contains(@text, 'Call')]")).isDisplayed())

回答by Lishani

By using the available properties - index and class name, you can try with the below xpath

通过使用可用的属性 - 索引和类名,您可以尝试使用以下 xpath

//android.widget.EditText[@index='2']

回答by Vignesh

u can do it in another way ,u know that there are 5 textfields , hence write the code as below.

你可以用另一种方式来做,你知道有 5 个文本字段,因此编写如下代码。

driver.findelements(By.tagname("textfield")).get(0).sendkeys("[email protected]"));

driver.findelements(By.tagname("textfield")).get(0).sendkeys("[email protected]"));

this means that you are trying to pass the [email protected] value in the first text field "get(0)".

这意味着您正在尝试在第一个文本字段“get(0)”中传递 [email protected] 值。