0

現在、ロボティウムを使用して、Android Web ビューで一連のアクションを記録しています。robotium には、選択ボックスの値を変更できない既知のバグがあります。テストの実行中にこれに対処するために、別の JavaScript インジェクションを作成して変更しています。名前とIDで機能しますが、名前またはIDが利用できない場合に備えて、xpathも使用できる必要があります。

現時点では、次を使用して、選択ボックスの名前と ID を使用してこれを行うことができます。

selectBox = document.getElementById(identifyingValue);

また

selectBox = document.getElementByName(identifyingValue);

この後、選択ボックスの値を必要な値に変更するメソッドを作成できます。問題は、選択ボックスの ID または名前を取得できないことがあり、Xpath を介してこれを行う同様の方法がないことです。

selectBox = document.getElementByXpath(identifyingValue);

私のコードは現在次のようになっています。

var selectBox;
var identifyingAttribute = ('$identifyingAttribute');
var identifyingValue = ('$identifyingValue');
var selectedIndex = '$selectedIndex';
if (identifyingAttribute === 'id') {
    selectBox = document.getElementById(identifyingValue);
} else if (identifyingAttribute === 'name') {
    selectBox = document.getElementByName(identifyingValue);
} else if (identifyingAttribute === 'xpath') {
    selectBox = document.getElementByXpath(identifyingValue);   
}
selectBox.selectedIndex = selectedIndex;
if (selectBox.onchange) {
    selectBox.onchange();
}

これまでのところ、ID と名前を最初に使用し、最後の手段として xpath を使用しようとしていることがわかります。

Xpath で要素を選択し、その値を変更したり、同様のアクションを実行したりできますか。ヘルプやご意見をいただければ幸いです。

4

2 に答える 2

0

document.querySelector()を使用して、css セレクターでプロパティを選択できます。

ドキュメントはここにあります: https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector

于 2014-08-18T14:58:42.423 に答える
0

document.evaluate() を使用して問題の解決策を見つけました ステートメントは私のために機能します:

selectBox = document.evaluate(identifyingValue, document, null , 9, null).singleNodeValue;
于 2014-08-18T16:00:58.753 に答える