2016-06-29 10 views
0

javaを使用してセレンでチェックを入れるかどうかにかかわらず、チェックボックスのステータスを取得しようとしています。チェックボックスがJavaを使用してセレンでチェックされているかどうかを確認する

HTMLコード::

<div class="icheckbox_square-aero" style="position: relative;" aria-checked="false" aria-disabled="false"> 

<input id="IAgree" class="icheckbox_square-aero" type="checkbox" required="" name="IAgree" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;"> 

<ins class="iCheck-helper" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;"></ins> 
</div> 

プログラミングコード:: clickOnCheckboxため

String loc_iAgree = pr.getProperty("iagree_xpath"); 
//iagree_xpath is declared in properties file as "iagree_xpath = //form[@id='myWizard']/div/section[3]/div[3]/div/ins" 
uia.clickOnCheckbox("xpath", loc_iAgree); 

コード(:以下 は、HTMLのコードと私が書いたコードです)メソッド::

public void clickOnCheckbox(String loc_Type, String loc_Value) { 
    try { 
     if (loc_Type.equalsIgnoreCase("id")) { 
      element = driver.findElement(By.id(loc_Value)); 
     } else if (loc_Type.equalsIgnoreCase("name")) { 
      element = driver.findElement(By.name(loc_Value)); 
     } else if (loc_Type.equalsIgnoreCase("xpath")) { 
      element = driver.findElement(By.xpath(loc_Value)); 
     } else if (loc_Type.equalsIgnoreCase("linktext")) { 
      element = driver.findElement(By.linkText(loc_Value)); 
     } else if (loc_Type.equalsIgnoreCase("partiallinktext")) { 
      element = driver.findElement(By.partialLinkText(loc_Value)); 
     } else if (loc_Type.equalsIgnoreCase("cssSelector")) { 
      element = driver.findElement(By.cssSelector(loc_Value)); 
     } else { 
      System.out.println("provide valid locator Type"); 
     } 

     String value; 
     if (element.isEnabled()) { 
      element.click(); 
      value = element.getAttribute("checked"); 
      System.out.println(value); 
     } else { 
      System.out.println("element is not present or not enabled"); 
     } 
    } catch (Exception e) { 
     throw (e); 
    } 
} 

このチェックボックスがオンになっていても、値はnullを返します。

チェックボックスのステータスを呼び出し元のプログラムに戻す方法はありますか?セレンwebdriverを内

+0

[ '.isSelectedを()'](使用してみhttps://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/ WebElement.html#isSelected--)の代わりに 'isEnabled()'を使います。 – JRodDynamite

答えて

0

isSelected()

Link
関連する問題