2016-06-15 7 views
1

私はテストする必要があるAndroidアプリケーションにチェックボックスのリストを持っています。したがって、isSelected()メソッドを使用すると、このチェックボックスがオンになっているかどうかに関係なく、常にfalseが返されます。 findelementById()とbyXpath()を使用しようとしていました。同じ結果。CheckBox用のSelenium isSelected()メソッドは、常にAndroid用にfalseを返します。

WebElement checkBox = driver.findElementById(appType + id); 
    if (!checkBox.isSelected()){ 
     Reporter.log(backupDataType + " checkbox isn't checked. clicking on it...", true); 
     ...} 

XPathを使用:

は、ここで私が使用したもののコードの一部である、それは常にそれをクリックているため要素に

checkBox = driver.findElementByXPath("//android.widget.CheckBox[@resource-id='" + appType + checkSms + "']"); 
    if (!driver.findElementByXPath("//android.widget.CheckBox[@resource-id='" + appType + checkSms + "']").isSelected()){ 
    Reporter.log(backupDataType + " checkbox isn't checked. clicking on it...", true); 
    ...} 

パスは、正しいです。それがチェックされるかどうかは関係ありません。あなたはアンドロイドのチェックボックスウィジェットを使用している考慮

答えて

0

、あなたは PS follows-

WebElement element = <find element by your locator strategy>; // in your case driver.findElementByXPath("//android.widget.CheckBox[@resource-id='" + appType + checkSms + "']"); 
String checkboxAttribute = element.getAttribute("checked"); 
if(!checkboxAttribute.equalsIgnoreCase("true")) { 
    Reporter.log(backupDataType + " checkbox isn't checked. clicking on it...", true); 
    ... 
} 

としてWebElementgetAttributeプロパティを使用してみなければなら - WebElementを保存する代わりに、再びそれを見つけてみてくださいと実践。

+0

ありがとうございました!私は通常、節約のWeb要素。この場合、私はそれを動作させるために異なる組み合わせを試していました。 – DiTest

関連する問題