html code :
input type="checkbox" class="checkbox_one" disabled
if checkbox is not disable text is not coming.
Assert.assertTrue(webelemt.getAttribute("innerHTML").contains("disabled"));
CodePudding user response:
You can use....
ele = driver.find_element_by_class_name('checkbox_one')
if ele.is_selected():
// do something
else:
// do something
CodePudding user response:
disabled
is an attribute so try checking for its existence
<input id="myinput" type="checkbox" class="checkbox_one" disabled>
e.g.
Assert.assertNotNull(driver.findElement(By.id("myinput")).getAttribute("disabled"));
CodePudding user response:
You can call .getAttribute
method to have a condition where it will check for it's content and if that is not empty, assert should be pass, if empty assert should be fail.
Code :
WebElement webelemt = driver.findElement(By.xpath("//span[@title='fieldItem']//preceding-sibling::input"));
String checkBoxStatus = "";
if (!webelemt.getAttribute("disabled").isEmpty() && webelemt.getAttribute("disabled").contains("disabled")) {
System.out.println("Disabled must be present");
checkBoxStatus = "disabled";
Assert.assertTrue(true);
}
else {
System.out.println("Should not it be enabled ? or do we need if-else to handle that part as well.");
Assert.assertTrue(false);
}