2

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.

2 Answers 2

9

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;
  }
Sign up to request clarification or add additional context in comments.

1 Comment

@AlexeiLevenkov True enough. I hadn't thought beyond fixing the coding issue.
0

A shorter version:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.