Home > Net >  How to check if textbox is disabled in selenium C#
How to check if textbox is disabled in selenium C#

Time:03-17

I want to confirm and verify a textbox is disabled and not enabled

I tried below asserts, but it doesn't do the work

Assert.IsFalse(formPage.Name.Enabled);
Assert.AreEquals(null, formPage.Name.GetAttribute("value"));

Below is the Element for the textbox

<div >
    <lable >Name</label> 
    <input disabled  value> ==$0
</div>

CodePudding user response:

In selenium there is the .Enabled(), you could use that to check if it's enabled or not.

driver.FindElement(by).Enabled

it only works for input methods, if you want to check something that isn't a input method you should use GetAttribute("disabled"), that will return a bool value.

you can read more about the method in the docs

CodePudding user response:

You can assert the length of list returned from this command is not 0 i.e. the such element exists:

driver.FindElements(By.XPath("//input[@class='form-control first-name-input-large' and @disabled]"))
  • Related