Reputation: 131
i would like to assert whether a particular text box is disabled or enabled. below is the HTML
for it. the difference between the disabled and enabled text box is only By disabled
Attribute towards the end.
disabled text box HTML:
<input controlid="txtIPAddress" class="textfield form-control servicefield invItem_dynamic_validation valid" id="OrderProperties_4__Value" isdisabled="true" name="OrderProperties[4].Value" style="display:" type="text" value="" disabled="">
enagled text box HTML-
<input controlid="txtIPAddress" class="textfield form-control servicefield invItem_dynamic_validation valid" id="OrderProperties_4__Value" isdisabled="true" name="OrderProperties[4].Value" style="display:" type="text" value="">
I tried element.isEnabled()
and element.isEnabled()
methods to no avail.
any help much appreciated!
Upvotes: 1
Views: 11378
Reputation: 11
To Assert Text box editable, we can use isEnabled()
function.
See below sample,
boolean anytextfield = driver.findElement(By.xpath("respectivexpath")).isEnabled();
Assert.assertEquals(anytextfield,true);
Upvotes: 0
Reputation: 193078
As per the documentation isEnabled()
method is defined as:
boolean isEnabled()
Description:
Is the element currently enabled or not? This will generally return true for everything but disabled input elements.
Returns:
True if the element is enabled, false otherwise.
So your code trial as element.isEnabled()
was perfect to retrieve the status whether the element was enabled or not provided the element uniquely identified the node which you have provided within the question.
As an alternative you can try to validate if the elelemt is present without the attribute disabled using the following solution:
try {
driver.findElement(By.xpath("//input[@class='textfield form-control servicefield invItem_dynamic_validation valid' and not(disabled)][@controlid='txtIPAddress']"));
System.out.println("Element is enabled");
} catch (NoSuchElementException e) {
System.out.println("Element is not enabled");
}
Upvotes: 2