【问题标题】:How use non-static value in annotation FindsBy?如何在注解 FindsBy 中使用非静态值?
【发布时间】:2017-10-19 19:20:19
【问题描述】:

我试图使用 POM 将我的定位器的整个定义从标准格式转换为注释 FindsBy。但我有一些定位器,它们由非静态变量组成,我收到错误消息:“无法在静态上下文中访问非静态字段 _createBookData”。

我想得到的代码:

[FindsBy(How = How.CssSelector, Using ="#select-month > option:nth-child(" + _createBookData.NumberMonth + ")")  ]  private IWebElement BirthmonthDropItem;

代替这段代码:

 private IWebElement BirthmonthDropItem
    {            
        get
        {
            return _waitDriver.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("#select-month > option:nth-child(" + _createBookData.NumberMonth + ")")));
        }
    }

【问题讨论】:

    标签: c# selenium-webdriver annotations pageobjects


    【解决方案1】:

    你不能这样做。属性是并且必须在编译时完全定义,而不是在运行时。这正是 C# 语言的工作方式。这是设计使然;没有解决方法可以使用属性执行此操作。幸运的是,页面对象模型不依赖于使用PageFactory 实现。与其他填充页面对象的方法相比,使用 PageFactory 没有明显的好处。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      • 2010-12-16
      • 2012-06-01
      相关资源
      最近更新 更多