简体   繁体   中英

How to check if textbox is disabled in selenium C#

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 class="col-lg-4 col-md-4 col-sm-4">
    <lable class="placeholder">Name</label> 
    <input disabled class="form-control first-name-input-large" value> ==$0
</div>

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM