Reputation: 2922
I want to check whether button is disabled or not by selenium IDE
But I couldn't.
I have tried below code but it doesn't work. is there any other way to find whether button is disabled...? <tr><td>assertElementPresent</td><td>
//button[contains(text(), 'Save')]</td><td>/td></tr>
Upvotes: 19
Views: 89640
Reputation: 385
public boolean isAddToCartButtonEnabled(String machineName){
String addToCartButtonXpath = "//button[contains(text(),'sample')];
WebElement addToCartButton = driver.findElement(By.xpath(addToCartButtonXpath));
if (addToCartButton.isDisplayed() && addToCartButton.isEnabled()) {
System.out.println("Add to Bag button found and enabled");
return true;
} else {
System.out.println("Add to Bag button not found or not enabled, probably item out of stock");
return false;
}
}
Inspire From this code : addToCartButton.isDisplayed() && addToCartButton.isEnabled()
make sure you use NORMAL:
option.setPageLoadStrategy(PageLoadStrategy.NORMAL);
Upvotes: 0
Reputation: 23
instead of is_enable use get_property :
element = driver.find_element_by_name("element_name")
prop = element.get_property('disabled')
Upvotes: 1
Reputation: 1518
3 years later...I am using Selenium IDE to test whether the DOM button has been disabled:
Command: assert element present
Target: xpath=//button[@disabled]
now, I have an id for button as well, so I included that in the square bracket to ensure I am "looking" at the right button.
Hopefully, this helps somebody.
Upvotes: 4
Reputation: 2922
I got the answer by following way. I am getting all the style classes by using "window.document.getElementById('requiredId').className" and searching for required disable style class by following expression.
|assertExpression | javascript{storedVars['classname'].search("disabled-style-class") == -1} | false |
Upvotes: 1
Reputation: 2847
In WebDriver. There is a method isEnabled which returns true if the element is enabled else it returns false.
driver.findElement(By.id("elementID")).isEnabled();
Upvotes: 31
Reputation: 479
You can use VerifyNotEditable to check your Element,Button in this case..
Upvotes: 13
Reputation: 25056
A button can be disabled in many ways...so you will need to think about that but a simple solution would be the assertAttribute
command, using the attribute disabled
.
This will ensure the element has the disabled
value set, which is a common way to disable elements, but not the only way.
Upvotes: 2
Reputation: 5082
You can check the Element visibility by using the assertVisible
command.
Code:
Command =
assertVisible
Target =
Locator Value
Returns true
if the specified element is visible, false otherwise
Determines if the specified element is visible. An element can be rendered invisible by setting the CSS "visibility" property to "hidden", or the "display" property to "none", either for the element itself or one if its ancestors. This method will fail if the element is not present.
Upvotes: 0