从XML文件获取XPath

时间:2018-07-10 22:53:37

标签: xml xpath

是否有一种方法可以从此XML文件获取editText对象的XPath,并得到与该XPath类似的结果:

//*[@class='android.widget.FrameLayout' and ./parent::*[@id='key_pos_ime_action']]/*[@class='android.widget.ImageView'])[1]

这是XML文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="match_parent">
    <LinearLayout android:orientation="vertical" android:paddingLeft="24dp" 
                  android:paddingTop="56dp" 
                  android:paddingRight="24dp" 
                  android:layout_width="match_parent" 
                  android:layout_height="wrap_content">
        <ImageView android:layout_gravity="left|right|center_horizontal|fill_horizontal|center|fill|start|end" 
                   android:layout_width="wrap_content" android:layout_height="UNKNOWN_DATA_0x4801" android:layout_marginBottom="24dp" android:src="@drawable/logo" />
        <LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="UNKNOWN_DATA_0x0" android:layout_height="UNKNOWN_DATA_0x0" />
        <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:layout_marginBottom="8dp">
            <EditText android:id="@+id/input_email" 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content" 
            android:hint="Email" 
            android:inputType="text" /> 
        </android.support.design.widget.TextInputLayout>    <!-- added by edit -->
    </LinearLayout>                                         <!-- added by edit -->
</ScrollView>                                               <!-- added by edit -->

2 个答案:

答案 0 :(得分:0)

尝试此XPath

//LinearLayout/android.support.design.widget.TextInputLayout/EditText

并根据需要添加谓词。

答案 1 :(得分:0)

您可以参考

//EditText[@android:id='@+id/input_email']