2017-04-06 8 views
0

私はAndroid AppとAppiumのオートネーションでスクロール可能なリスト(検索結果)を持っていますが、そこから特定の要素を選択する必要があります。 Appiumインスペクタは、index、resource-id、xpathなどの情報を提供しています。xアンドロイドのリスト要素のパス(appiumオートメーションを使用)

content-desc: 
type: android.widget.TextView 
text: AMI 
index: 0 
enabled: true 
location: {60, 513} 
size: {81, 61} 
checkable: false 
checked: false 
focusable: false 
clickable: false 
long-clickable: false 
package: com.abc.xyz.debug 
password: false 
resource-id: com.abc.xyz.debug:id/student_label_text 
scrollable: false 
selected: false 

(appiumインスペクタによって提供される)最初の結果のXPathは次のようである:

//android.support.v7.widget.RecyclerView[1]/android.widget.FrameLayout[1] /android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget。 RelativeLayout [1] /android.widget.LinearLayout [1] /android.widget.LinearLayout [1] /android.widget.TextView [1] seconため

それは...

//android.support.v7.widget.RecyclerView[1]/android.widget.FrameLayout[2]/android.widget.FrameLayout[1]/android.widget.LinearLayoutある結果dは[1] /android.widget.LinearLayout [1] /android.widget.LinearLayout [1] /android.widget.FrameLayout [1] /android.widget.RelativeLayout [1] /android.widget.LinearLayout [1] /アンドロイド.widget.LinearLayout [1] /android.widget.TextView [1]

上記のxPathsは動作しますが、私はより短いバージョンを探しています。私は様々な組み合わせを試しましたが、私はこれに新しいので、解決策を見つけることができません。この仕事やこの仕事をすることができるツールに関する助け?

+1

をすることができますuの最後のTextViewの詳細を提供するappium inspectorに表示される – SaiPawan

+0

@sai更新情報 – TestingWithArif

+0

答えを確認 – SaiPawan

答えて

1

通常、Xpathでの最適な選択は、要素の任意の属性で一意の値を見つけることです。 XPathは、他の検索戦略よりも遅いので、あなたが最初のIDと一致するすべての要素を取得し、その後、それらの要素が持っている値がどのような属性チェックすることができ

driver.findElement(By.xpath("//android.widget.TextView[@text='AMI']")); 

:あなたの例の値から、あなたはテキスト値で見つけることができます:

List<MobileElement> elements = driver.findElements(By.id("com.abc.xyz.debug:id/student_label_text")); 
for (MobileElement element : elements) { 
    if (element.getAttribute("text") == "AMI") { 
     element.click(); 
    } 
} 

私はfindElementの代わりにfindElementsを使用して、すべての一致する要素のリストを取得しています。

のgetAttributeコマンドの使用方法は非常によく文書化されていない..ですこれは、属性のすべての受け入れの名前を見つけるために掘る一部を取っ:

https://github.com/appium/appium-android-bootstrap/blob/master/bootstrap/src/io/appium/android/bootstrap/AndroidElement.java#L182

https://github.com/appium/appium-android-bootstrap/blob/master/bootstrap/src/io/appium/android/bootstrap/AndroidElement.java#L94

1

XPathではなく、idを正しく使用できます。

driver.findElement(By.id("student_label_text")) 

XPathは要素を識別するためのIDと比較してはるかに時間がかかります。下記のようにIDを使用することができます私たちのscripts.Weの実行速度に影響を与えるだろうXPathを使用し

+0

私はトライそれ以前に。問題は、私は同じIDを持つ複数の結果があります。だから私はこれを使用して複数の結果を返します(#は異なる可能性があります)。 xPathは、必要に応じて第1または第2の結果を選択できるという点で、使い勝手が良かったようです。 – TestingWithArif

+1

次に、あなたはxpathの代わりにこれを行うことができます。xpathは最初に取得するget(0)のように、driver.findElements(By.id( "com.abc.xyz.debug:id/student_label_text"))を使用できます。お勧めしません – SaiPawan

+0

ありがとうございます。私はこれを試して更新します。 – TestingWithArif

関連する問題