Get XPath value from xml file

I’m trying to get editText XPath from the xml file and use it in my test script
When I spy the editText object I get this XPath

//hierarchy/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.EditText[1]

But when I try to get the Xpath form the xml file I get

/ScrollView[@xmlns:android=“http://schemas.android.com/apk/res/android"]/LinearLayout[@android:orientation=“vertical”]/android.support.design.widget.TextInputLayout[@android:layout_width=“match_parent”]/EditText[@android:id="@+id/input_email”]

and when I try to use it I get

Test Cases/xpath test FAILED because (of) org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.

Is there any way to reform the second Xpath and get a result like the first one ?

1 Like