Tanmoy Ray Tanmoy Ray - 1 month ago 15
Android Question

How to fix "Can't locate an element by this strategy: Locator map:"

Can't locate an element by this strategy:

Locator map: - native content: "By.xpath: //android.widget.ImageView[id='toolbar_search_place']" - html content: "by id or name "ClkSearchicon""


I have added 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>




Answer

If you are looking only by the ID value the correct solution should be following: By.id("toolbar_search_place")

If you are using resource-id attribute then you have to match exact value from the page element XML e.g. By.xpath("//android.widget.ImageView[@resource-id='<resource_id_value>']")

NOTE! resource-id =/= id

UPDATE!

So in this particular XML case your xpath should look like following:

By.xpath("//android.widget.ImageView[@resource-id='com.senrysa.veiculu:id/toolbar_search_place']")

More information about XPath: W3schools XML and XPath