简体   繁体   English

Selenium C#-断言输入字段已禁用问题

[英]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. 我在C#中使用Selenium WebDriver,如果输入字段被禁用,我试图断言。 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. 我试图将IsFalse更改为IsTrue,还返回false,返回true顺序,但是似乎无法获得我想要的正确结果。

Any help would be greatly appreciated. 任何帮助将不胜感激。

Your code will always return false because of the ; 由于;您的代码将始终返回false ; at the end of the if . 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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