Sree
Sree

Reputation: 2922

How to find whether button is disabled or not in Selenium IDE

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

Answers (8)

roudlek
roudlek

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

user3718964
user3718964

Reputation: 23

instead of is_enable use get_property :

element = driver.find_element_by_name("element_name")
prop = element.get_property('disabled')

Upvotes: 1

Johnny Wu
Johnny Wu

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

Sree
Sree

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-cl‌​ass") == -1} | false |

Upvotes: 1

Code Enthusiastic
Code Enthusiastic

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

Virendra Joshi
Virendra Joshi

Reputation: 479

You can use VerifyNotEditable to check your Element,Button in this case..

Upvotes: 13

Arran
Arran

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

Manigandan
Manigandan

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

Related Questions