16

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>

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
Sree
  • 2,792
  • 8
  • 25
  • 33

8 Answers8

30

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();
Roy Shmuli
  • 4,979
  • 1
  • 24
  • 38
Code Enthusiastic
  • 2,827
  • 5
  • 25
  • 39
12

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

Virendra Joshi
  • 469
  • 4
  • 8
  • 25
2

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.

Arran
  • 24,648
  • 6
  • 68
  • 78
  • Hi All, 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 that |assertExpression | javascript{storedVars['classname'].search("disabled-style-class") == -1} | false | – Sree Feb 18 '13 at 11:02
2

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.

Johnny Wu
  • 1,297
  • 15
  • 31
1

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 |
Sree
  • 2,792
  • 8
  • 25
  • 33
  • how did you store window.document.getElementById('requiredId').className in storedVars['classname'] ? @Sree – walox Feb 15 '18 at 16:42
1

instead of is_enable use get_property :

element = driver.find_element_by_name("element_name")
prop = element.get_property('disabled')
user3718964
  • 23
  • 1
  • 7
0

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.

Manigandan
  • 5,004
  • 1
  • 28
  • 47
  • Thank you Manigandan,But I need to find whether button is disabled or not. I think we don't have command like assertDisable. is there any other way to find whether button is disabled or not ? – Sree Feb 18 '13 at 05:51
  • What do you mean by `Disable?` – Manigandan Feb 18 '13 at 06:13
0
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);
roudlek
  • 160
  • 9