2017-06-23 27 views
0

私はWDを使用してnodejs上appium(アンドロイドブラックボックステスト)問題を持っています。 IDは一意ではなく、スキーマは常に同じです - >Appium +(nodejsは)兄弟要素

ListView 
    | 
    | 
    Frame 
    | | 
    | | 
    | TextView[@text headline0] 
    | | 
    | | 
    | Button //no text - just an icon 
    | 
    Frame 
    | | 
    | | 
    | TextView[@text headline1] 
    | | 
    | | 
    | Button //no text - just an icon 
    | 
    Frame 
    | | 
    ... 

私の問題は、たとえば次のボタンをクリックしたいということです。見出し9。 [//Frame[@index="9"]/]のようなxp​​athを使用することはできませんが、インデックスが現在表示されている領域の0から再び始まるように思われるため... [//Frame[@index="9"]/]だから多分@index="9"@index=2または時々@index=1 ...

が今のようなものを使用して、ボタンを選択することが私の考えですとなりました:

.elementByXPath("//android.widget.TextView[@text='headline9']/../android.widget.Button") 

をしかし、

(要素を見つけることができない)動作しないようです

他の誰かがアイデアを持っていますか?

ありがとうございます!

答えて

0

すべてのTextViewをelementsByXPath()で取得してから、すべてのボタンを同じ方法で試してください。 TextViews Textが "headline9"と等しい場合はButtonを返し、見つかったTextViewsを反復処理します。目に見える場所でそれを見つけることができない場合は、スクロールしてもう一度やり直してください。

new Promise(function (resolve, reject) { 
(function yourfunctionId(id, context){ 
    elementsByXPath(Frame[@index=id]TextView){ 
    elementsByXPath(Frame[@index=id]Button){ 
    if(TextView[0] === 'undefined'){ 
    //scroll in ListView 
    //call your function recursively from begin (id =0) 
    yourfunction(0) 
    } 
    if(TextView[0].getAttribute('name') == 'headline9'){ 
    return Button[0] 
    } 
    else{ 
    //next 
    //call your function recursively 
    yourfunction(id++) 
    } 
    } 
    } 
)} 

あなたはフォン・フレーム・エレメントのサイズにスクロールするか、あなたは多分チェックしなければならないのどちらかが初のフレームイストが部分的に見えています。

0

私は、これは

var elemList = yield driver.elementsByClassName('android.support.v7.widget.LinearLayoutCompat'); //get List of elements 
for(let elem of elemList) { 
    //traverse list of elements 
    let text = yield elem.elementById('subElementId').text(); //find subElement 
    //Your code logic 
} 

は、要素のリストを取得し、その後、サブ要素を見つけることができます願っています。私は "yiewd"ライブラリを使用しています、 "wd"のコンセプトは同じです。 ありがとう!

関連する問題