【问题标题】:Get XPath from XML file从 XML 文件中获取 XPath
【发布时间】:2018-07-10 22:53:36
【问题描述】:

有没有办法从这个 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 -->

【问题讨论】:

  • 我在您的 XML 示例中添加了三个结束标记,以使其格式良好

标签: xml xpath


【解决方案1】:

试试这个 XPath

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

并根据需要添加谓词。

【讨论】:

    【解决方案2】:

    你可以参考这个,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多