<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<hierarchy rotation="0">
-<node bounds="[0,0][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.widget.FrameLayout" resource-id="" text="" index="0">
-<node bounds="[0,0][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.widget.LinearLayout" resource-id="" text="" index="0">
-<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.widget.FrameLayout" resource-id="android:id/content" text="" index="0">
-<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.webkit.WebView" resource-id="" text="" index="0">
-<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="true" focused="true" focusable="true" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.webkit.WebView" resource-id="" text="Ionic App" index="0">
-<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
-<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
-<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
-<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
-<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
-<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0"/>
-<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="1">
-<node bounds="[0,42][720,1280]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
-<node bounds="[0,42][720,80]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
<node bounds="[631,42][720,80]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="true" enabled="true" clickable="true" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.widget.Button" resource-id="" text="V 3.5" index="0"/>
</node>
<node bounds="[190,105][530,229]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.widget.Image" resource-id="" text="Himalaya Image" index="1"/>
<node bounds="[288,262][432,369]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.widget.Image" resource-id="" text="Leap Image" index="2"/>
-<node bounds="[35,483][687,628]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="3">
-<node bounds="[131,483][589,565]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
-<node bounds="[131,483][589,565]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
-<node bounds="[131,483][589,563]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
-<node bounds="[131,483][589,563]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="0">
<node bounds="[145,504][575,539]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="true" enabled="true" clickable="true" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.widget.EditText" resource-id="" text="" index="0" NAF="true"/>
<node bounds="[131,483][589,565]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="true" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="1" NAF="true"/>
</node>
</node>
</node>
</node>
-<node bounds="[35,596][687,628]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="1">
<node bounds="[224,602][390,628]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="true" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="Register" index="0"/>
<node bounds="[388,596][397,628]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text=" " index="1"/>
<node bounds="[393,602][497,628]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="true" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="Forgot PIN" index="2"/>
</node>
</node>
<node bounds="[101,745][619,1106]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.widget.Image" resource-id="" text="Lead 2020" index="4"/>
</node>
</node>
</node>
</node>
</node>
</node>
<node bounds="[0,42][720,45]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="" text="" index="1"/>
</node>
</node>
</node>
</node>
</node>
</node>
<node bounds="[0,0][720,42]" selected="false" password="false" long-clickable="false" scrollable="false" focused="false" focusable="false" enabled="true" clickable="false" checked="false" checkable="false" content-desc="" package="com.talentpace.substk" class="android.view.View" resource-id="android:id/statusBarBackground" text="" index="1"/>
</node>
</hierarchy>
已检查的元素。尝试通过各种方式在代码中查找元素。但是没有任何效果。请建议在应用中编辑PIN码的xpath应该是什么
附上我要为其编写代码的树
下面是我尝试过的xpath
driver.findElementByXPath(“ // android.widget.FrameLayout // android.view.View [@ index ='3'] // android.widget.EditText”)
答案 0 :(得分:1)
这不能回答问题,但是如果您可以访问源代码,则可能会有所帮助。 setContentDescription方法有助于解决此类问题,它必须以XML进行定义,这不仅对可访问性有帮助,而且在进行任何UI测试期间也有帮助。即使您有ID /文本,也可能是多个视图具有相似的文本和/或ID
在您的情况下-XPath中的元素分割应使用一个斜杠“ /”完成 这是一个示例
driver.findElement(By.xpath("//android.widget.FrameLayout[1]/android.view.View[3]/android.widget.EditText[0]"));
答案 1 :(得分:0)
在XPath表达式中,您尝试获取所有<android.widget.FrameLayout[1]>
元素。查看xml,文档中仅有的元素是一个<hierarchy>
和多个<node>
元素。这就是为什么您没有任何结果的原因。
假设您正在使用C#进行编码,请尝试如下操作:
driver.findElementByXPath(@"//node[@class = ""android.widget.EditText""]));
//node
返回所有<node>
元素
在当前的xml文档中。[@class = ""android.widget.EditText""]
告诉您的XPath表达式您需要带有带有值的class属性的元素
等于“ android.widget.EditText”。请注意,使用//不是查询xml的非常有效的方法。始终尝试避免它并使XPath表达式变窄。 Microsoft here的一个不错的XPath示例列表\备忘单。它应该可以帮助您实现这一目标。