gpt4 book ai didi

android - 如何在android中使用appium uiautomatorviewer创建xpath?

转载 作者:行者123 更新时间:2023-11-30 01:52:49 25 4
gpt4 key购买 nike

如何使用 UI automator 查看器创建 XPath。目前我正在测试移动网络应用程序。在这里我需要识别对象属性,我尝试使用由 Firebug 和相关 XPath 识别的属性,但它无法锻炼。您能否指导我如何在 android 中使用 appium UI automator 查看器创建 XPath?

我在 windows 机器上使用 android。我想在移动网络浏览器中获取对象的 ID、名称和 XPath。

enter image description here

设置如下:

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);

最佳答案

在 Appium 框架中,XPath 语法与 @Gaurav 提到的 Web 中使用的语法有点不同。

如果您打印 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']");

关于android - 如何在android中使用appium uiautomatorviewer创建xpath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32747203/

25 4 0
文章推荐: C++ 工厂。子构造函数不能从父访问
文章推荐: c++ - 在模板推导中保留函数指针参数的完整类型
文章推荐: c++ - 在构造函数中传递指向对象的指针
文章推荐: java - List 和 List 之间有什么区别?