ist Ich versuche, den Status des Kontrollkästchens, ob in Selen mit Java überprüft oder nicht. Unten ist der Code des HTML und der Code, den ich geschrieben habe:Wie zu wissen, ob ein Kontrollkästchen in Selen mit Java
HTML Code ::
<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>
Programmiercode ::
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);
Code für clickOnCheckbox () Methode ::
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);
}
}
Hier gibt der Wert null zurück, auch wenn das Kontrollkästchen aktiviert ist.
Gibt es eine andere Möglichkeit, den Status der Checkbox zurück zum aufrufenden Programm zu bekommen ??
Versuchen Sie es mit [ '.isSelected()'] (https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/ WebElement.html # isSelected--) anstelle von 'isEnabled()'. – JRodDynamite