【问题标题】:Selenium override FindsBy attribute in derived classSelenium 覆盖派生类中的 FindsBy 属性
【发布时间】:2017-10-11 09:19:24
【问题描述】:

我使用带有 PageFactory 的页面对象模型模式来初始化 IWebElement 属性/字段。我的问题是我希望派生类使用不同的 [FindsBy] 属性覆盖 IWebElement。我的基类:

public class ConfigurationMenuPage : PageInfo, IConfigurationMenuPage
{
    private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

    [FindsBy(How = How.Id, Using = "ctl00_contents_ctl27")]
    protected virtual IWebElement _campaignsConfigLink { get; set; }

还有我的派生类:

 public class ConfigurationMenuPage21 : ConfigurationMenuPage
 {
    [FindsBy(How = How.Id, Using = "otherId")]
    protected sealed override IWebElement _campaignsConfigLink { get; set; }

问题在于_campaignsConfigLink 属性使用基本属性初始化(id 为“ctl00_contents_ctl27”),而不是覆盖了一个(id 为 otherId)。如何强制覆盖的属性使用其 FindsBy 属性进行初始化?

问候,

Cybul26

【问题讨论】:

    标签: c# selenium attributes overriding


    【解决方案1】:

    为什么不直接删除ConfigurationMenuPage 中的声明并让派生类声明呢?一种解决方法是使用带有 OR 运算符的 CSS 选择器 #ctl00_contents_ctl27, #otherId

    【讨论】:

    • 感谢重播。我决定将ConfigurationMenuPage 做一个具有抽象属性的抽象类,并让派生类来声明它的属性。
    猜你喜欢
    • 1970-01-01
    • 2021-08-31
    • 1970-01-01
    • 2017-07-05
    • 1970-01-01
    • 2012-06-02
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多