简体   繁体   中英

Selenium C# - Assert that an input field is disabled issue

I'm using Selenium WebDriver with C# I am trying to Assert if an input field is disabled. My Solution has two projects a Tests and a Test Framework.

Tests

Assert.IsFalse(ContactPage.FirstNameDisabled, "Error: First Name field is not enabled");

Test Framework

  get
        {
            var firstName = Driver.Instance.FindElement(By.Id("FirstName"));
            if (firstName.Enabled);
             return false;
            return true;
        }

The above code passes whether the fields are disabled or not. I have tried to change around the IsFalse to IsTrue and also the return false, return true order however can't seem to get correct result I want.

Any help would be greatly appreciated.

Your code will always return false because of the ; at the end of the if . This change should fix it:

 get
 {
     var firstName = Driver.Instance.FindElement(By.Id("FirstName"));
     if (firstName.Enabled)
         return false;
     return true;
  }

A shorter version:

get
{
    return !Driver.Instance.FindElement(By.Id("FirstName")).Enabled;
}

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