简体   繁体   English

如何在Android中使用Appium uiautomatorviewer创建XPath?

[英]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.

相关问题 使用Appium的Xpath for Android元素 - Xpath for Android element using Appium 如何在Appium for Android中使用XPath在表格布局中查找元素 - How to find an element inside a tablelayout using xpath in appium for android 需要使用appium为android元素识别xpath - Need to identify xpath for android element using appium 如何正确设置 UiAutomatorViewer 以检查元素以使用 Appium 测试 Android 应用程序? - How to correctly set up UiAutomatorViewer to inspect elements for testing Android apps with Appium? Android - Uiautomatorviewer - 如何使用 Uiautomatorviewer 查看 uiautomator 转储视图。xml 文件? - Android - Uiautomatorviewer - How to view uiautomator dump view.xml file using Uiautomatorviewer? Appium - 无法使用 xpath 定位 android 元素 - Appium - Unable to locate android element using xpath Android中列出元素的xPath(使用appium自动化) - xPath for listing element in android (using appium automation) 将Xpath与Appium一起用于本机Android应用程序的问题 - Issue using xpath with appium for native android apps 如何使用appium在移动应用程序中找到xpath - How to find xpath in mobile app using appium 如何使用Studio在Android中设置环境变量以激活uiautomatorviewer - how to set environment variable for activate uiautomatorviewer in android using studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM