无法通过此策略找到元素:
Locator map: - native content: "By.xpath: //android.widget.ImageView[id='toolbar_search_place']" - html content: "by id or name "ClkSearchicon""
我添加了XML:
<?xml version="1.0" encoding="UTF-8"?><hierarchy rotation="0"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" 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][720,1184]" resource-id="" instance="0"><android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.senrysa.veiculu" 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][720,1184]" resource-id="" instance="0"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" 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][720,1184]" resource-id="" instance="1"><android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.senrysa.veiculu" 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][720,1184]" resource-id="com.senrysa.veiculu:id/action_bar_root" instance="1"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" 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][720,1184]" resource-id="android:id/content" instance="2"><android.support.v4.widget.DrawerLayout index="0" text="" class="android.support.v4.widget.DrawerLayout" package="com.senrysa.veiculu" 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][720,1184]" resource-id="com.senrysa.veiculu:id/drawer_layout" instance="0"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" 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,48][720,1184]" resource-id="" instance="3"><android.widget.RelativeLayout index="0" text="" class="android.widget.RelativeLayout" package="com.senrysa.veiculu" 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,48][720,1184]" resource-id="com.senrysa.veiculu:id/frame_container1" instance="0"><android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.senrysa.veiculu" 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,48][720,1184]" resource-id="" instance="2"><android.widget.LinearLayout NAF="true" index="0" text="" class="android.widget.LinearLayout" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,904][720,1184]" resource-id="com.senrysa.veiculu:id/ll_radious" instance="3"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" 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,904][720,1184]" resource-id="" instance="4"><android.widget.SeekBar index="0" text="" class="android.widget.SeekBar" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,904][720,1028]" resource-id="com.senrysa.veiculu:id/range" instance="0"/><android.widget.LinearLayout index="1" text="" class="android.widget.LinearLayout" package="com.senrysa.veiculu" 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,1044][720,1184]" resource-id="" instance="4"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" 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,1044][132,1164]" resource-id="" instance="5"><android.widget.ImageView index="0" text="" class="android.widget.ImageView" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[6,1044][126,1164]" resource-id="com.senrysa.veiculu:id/rd_seltct_marker_one" instance="0"/></android.widget.FrameLayout><android.view.View index="1" text="" class="android.view.View" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[132,1044][150,1184]" resource-id="" instance="0"/><android.widget.FrameLayout index="2" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[150,1044][282,1164]" resource-id="" instance="6"><android.widget.ImageView NAF="true" index="0" text="" class="android.widget.ImageView" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[156,1044][276,1164]" resource-id="com.senrysa.veiculu:id/rd_marker_two" instance="1"/></android.widget.FrameLayout><android.view.View index="3" text="" class="android.view.View" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[282,1044][300,1184]" resource-id="" instance="1"/><android.widget.FrameLayout index="4" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[300,1044][432,1164]" resource-id="" instance="7"><android.widget.ImageView NAF="true" index="0" text="" class="android.widget.ImageView" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[306,1044][426,1164]" resource-id="com.senrysa.veiculu:id/rd_marker_three" instance="2"/></android.widget.FrameLayout><android.view.View index="5" text="" class="android.view.View" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[432,1044][450,1184]" resource-id="" instance="2"/><android.widget.FrameLayout index="6" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[450,1044][582,1164]" resource-id="" instance="8"><android.widget.ImageView NAF="true" index="0" text="" class="android.widget.ImageView" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[456,1044][576,1164]" resource-id="com.senrysa.veiculu:id/rd_marker_four" instance="3"/></android.widget.FrameLayout><android.view.View index="7" text="" class="android.view.View" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[582,1044][600,1184]" resource-id="" instance="3"/><android.widget.FrameLayout index="8" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[600,1044][720,1164]" resource-id="" instance="9"><android.widget.ImageView NAF="true" index="0" text="" class="android.widget.ImageView" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[600,1044][720,1164]" resource-id="com.senrysa.veiculu:id/rd_marker_five" instance="4"/></android.widget.FrameLayout></android.widget.LinearLayout></android.widget.FrameLayout></android.widget.LinearLayout></android.widget.LinearLayout></android.widget.RelativeLayout><android.widget.RelativeLayout index="1" text="" class="android.widget.RelativeLayout" package="com.senrysa.veiculu" 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,48][720,1184]" resource-id="com.senrysa.veiculu:id/frame_container" instance="1"><android.widget.RelativeLayout index="0" text="" class="android.widget.RelativeLayout" package="com.senrysa.veiculu" 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,48][720,1184]" resource-id="" instance="2"><android.widget.RelativeLayout index="0" text="" class="android.widget.RelativeLayout" package="com.senrysa.veiculu" 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,48][720,1184]" resource-id="" instance="3"><android.widget.LinearLayout index="0" text="" class="android.widget.LinearLayout" package="com.senrysa.veiculu" 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,48][720,1184]" resource-id="com.senrysa.veiculu:id/rlUpperlayout" instance="5"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" 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,48][720,1184]" resource-id="" instance="10"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][720,1184]" resource-id="com.senrysa.veiculu:id/mapView" instance="11"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" 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,48][720,1184]" resource-id="" instance="12"><android.widget.RelativeLayout index="0" text="" class="android.widget.RelativeLayout" package="com.senrysa.veiculu" 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,48][720,1184]" resource-id="" instance="4"><android.widget.ImageView index="0" text="" class="android.widget.ImageView" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[10,1130][130,1174]" resource-id="" instance="5"/></android.widget.RelativeLayout><android.view.View index="1" text="" class="android.view.View" package="com.senrysa.veiculu" content-desc="Google Map" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][720,1184]" resource-id="" instance="4"><android.view.View index="0" text="" class="android.view.View" package="com.senrysa.veiculu" content-desc="0." checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[256,676][336,776]" resource-id="" instance="5"/></android.view.View><android.widget.RelativeLayout index="2" text="" class="android.widget.RelativeLayout" package="com.senrysa.veiculu" 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,48][720,1184]" resource-id="" instance="5"/></android.widget.FrameLayout></android.widget.FrameLayout><android.widget.LinearLayout index="1" text="" class="android.widget.LinearLayout" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[312,508][408,604]" resource-id="com.senrysa.veiculu:id/locationMarker" instance="6"><android.widget.ImageView index="0" text="" class="android.widget.ImageView" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[312,508][408,604]" resource-id="com.senrysa.veiculu:id/imageView_center" instance="6"/></android.widget.LinearLayout><android.widget.ImageButton index="2" text="" class="android.widget.ImageButton" package="com.senrysa.veiculu" content-desc="My Location" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[648,580][720,652]" resource-id="com.senrysa.veiculu:id/myMapLocationButton" instance="0"/></android.widget.FrameLayout></android.widget.LinearLayout></android.widget.RelativeLayout></android.widget.RelativeLayout></android.widget.RelativeLayout><android.view.ViewGroup index="2" text="" class="android.view.ViewGroup" package="com.senrysa.veiculu" 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,48][720,160]" resource-id="com.senrysa.veiculu:id/toolbar" instance="0"><android.widget.ImageButton index="0" text="" class="android.widget.ImageButton" package="com.senrysa.veiculu" content-desc="Navigate up" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,48][112,160]" resource-id="" instance="1"/><android.widget.LinearLayout index="1" text="" class="android.widget.LinearLayout" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[112,49][720,159]" resource-id="" instance="7"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[112,49][720,159]" resource-id="" instance="13"><android.widget.FrameLayout index="0" text="" class="android.widget.FrameLayout" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[480,49][720,159]" resource-id="" instance="14"><android.widget.ImageView NAF="true" index="0" text="" class="android.widget.ImageView" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[490,59][580,149]" resource-id="com.senrysa.veiculu:id/toolbar_search_place" instance="7"/><android.widget.ImageView NAF="true" index="1" text="" class="android.widget.ImageView" package="com.senrysa.veiculu" content-desc="" checkable="false" checked="false" clickable="true" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[620,59][710,149]" resource-id="com.senrysa.veiculu:id/btn_filter1" instance="8"/></android.widget.FrameLayout></android.widget.FrameLayout></android.widget.LinearLayout></android.view.ViewGroup></android.widget.FrameLayout></android.support.v4.widget.DrawerLayout></android.widget.FrameLayout></android.widget.LinearLayout></android.widget.FrameLayout></android.widget.LinearLayout><android.view.View index="1" text="" class="android.view.View" package="com.senrysa.veiculu" 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][720,48]" resource-id="android:id/statusBarBackground" instance="6"/><android.view.View index="2" text="" class="android.view.View" package="com.senrysa.veiculu" 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,1184][720,1280]" resource-id="android:id/navigationBarBackground" instance="7"/></android.widget.FrameLayout></hierarchy>
&#13;
答案 0 :(得分:1)
如果您只查看ID值,则应遵循以下正确解决方案:
By.id("toolbar_search_place")
如果您使用resource-id
属性,那么您必须匹配页面元素XML中的精确值,例如By.xpath("//android.widget.ImageView[@resource-id='<resource_id_value>']")
注意! resource-id
= / = id
<强>更新<!/强>
因此,在这个特定的XML情况下,您的xpath应如下所示:
By.xpath("//android.widget.ImageView[@resource-id='com.senrysa.veiculu:id/toolbar_search_place']")
有关XPath的更多信息:W3schools XML and XPath
答案 1 :(得分:0)
可接受的答案是正确的。
更多改进。
WebDriverWait wait;
public HpSancSignInME(AndroidDriver<MobileElement> driver) {
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
wait = new WebDriverWait(driver, 60);
}
public MobileElement getSignBtn() {
wait.until(ExpectedConditions.elementToBeClickable(signBtn));
return signBtn;
}