如何使用UI automator viewer创建XPath。目前我正在测试移动Web应用程序。在这里,我需要识别对象属性,我试图使用firebug和相对XPath识别的属性,但它无法锻炼。 你能指导我如何使用android中的appium UI automator viewer创建XPath吗?
我在windows机器中使用android。我想在移动网络浏览器中获取对象的ID,名称和XPath。
以下设置:
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);
答案 0 :(得分:0)
如果你想在上面的窗口中创建xpath,它将是这样的:
driver.findElementsByXPath("//*[@content-desc='No' and @index='16']");
只需根据需要不断更改参数。
答案 1 :(得分:0)
在Appium框架中,XPath语法与Web中使用的语法略有不同,如@Gaurav所述。
如果要打印XML页面源,您将更容易理解结构。这是一个例子:
<?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>
所以在你的情况下找到代码所遵循的元素:
driver.findElement(MobileBy.xpath("//android.widget.CheckBox[@index='1']"))
@Gaurav的例子在逻辑上也是正确的,但明星不应该像这样:
driver.findElementsByXPath("//[@class='android.widget.CheckBox' and @index='1']");