[英]How to creath xpath using appium uiautomatorviewer in android?
How to create XPath using UI automator viewer. 如何使用UI自动查看器创建XPath。 Currently I am testing mobile web applications. 目前,我正在测试移动Web应用程序。 Here I need to identify object properties, i have tried to use properties identified by firebug and relative XPath but it could not workout. 在这里,我需要确定对象属性,我尝试使用由萤火虫和相对XPath标识的属性,但无法进行锻炼。 Could you please guide me how to create XPath using appium UI automator viewer in android ? 您能否指导我如何使用android中的appium UI自动查看器创建XPath?
I am using android in windows machine. 我在Windows机器中使用android。 I would like to get ID, name and XPath of the objects in mobile web browser. 我想在移动Web浏览器中获取对象的ID,名称和XPath。
Setup below: 设置如下:
public void Appium() throws MalformedURLException{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Browser");
capabilities.setCapability(CapabilityType.VERSION, "5.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName","097f2163010ad15f");
capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
capabilities.setCapability("app", "chrome");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
If you want to create xpath in your window above, it would be like this: 如果要在上面的窗口中创建xpath,则如下所示:
driver.findElementsByXPath("//*[@content-desc='No' and @index='16']");
Just keep changing the parameters as per your need. 只需根据需要不断更改参数即可。
In Appium framework XPath syntax is a bit different from the one used in Web as @Gaurav mentions. 在Appium框架中,XPath语法与@Gaurav提到的Web中使用的语法有点不同。
If you would print the XML page source it would be a bit more easier for you to understand the structure. 如果您要打印XML页面源代码,那么您将更容易理解结构。 Here is an example: 这是一个例子:
<?xml version="1.0" encoding="UTF-8"?>
<hierarchy rotation="0">
<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.test" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1776]" resource-id="" instance="0">
<android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.test" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1080,1776]" resource-id="" instance="0">
<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.test" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,75][1080,1776]" resource-id="" instance="1">
<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.test" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,75][1080,1776]" resource-id="com.test:id/action_bar_root" instance="2">
<android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.test" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,75][1080,1776]" resource-id="android:id/content" instance="3">
<android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.test" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,75][1080,1776]" resource-id="" instance="1"/>
</android.widget.FrameLayout>
</android.widget.FrameLayout>
</android.widget.FrameLayout>
</android.widget.LinearLayout>
</android.widget.FrameLayout>
</hierarchy>
So in Your case to find element the code would be following: driver.findElement(MobileBy.xpath("//android.widget.CheckBox[@index='1']"))
因此,在您要查找元素的情况下,代码如下: driver.findElement(MobileBy.xpath("//android.widget.CheckBox[@index='1']"))
@Gaurav's example also is logically correct but the star should not be there like this: driver.findElementsByXPath("//[@class='android.widget.CheckBox' and @index='1']");
@Gaurav的示例在逻辑上也是正确的,但是星星不应该像这样: driver.findElementsByXPath("//[@class='android.widget.CheckBox' and @index='1']");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.