簡體   English   中英

使用資源文件c#Selenium的FindsBy屬性

[英]FindsBy attribute with resource file c# Selenium

在selenium中使用PageObject模式,我想將所有定位器放在資源文件中。

想知道是否可以在資源文件中使用FindsBy屬性

[FindsBy(How = How.Id, Using = "btnUserApply")]
public Button ApplyButton { get; set; }

如下所示會產生錯誤而無法完成

 [FindsBy(How = How.Id, Using = MyRexFile.btnUserApply)]
 public Button ApplyButton { get; set; }

FindsBy也是密封的,所以不能繼承。

有什么建議么?

這是不可能的。 FindsBy注釋接收const(在編譯時評估)字符串作為Using參數。 資源文件中的數據在運行時進行評估。

您可以創建另一個類來保存所有定位器

public static class Locators
{
    public const string btnUserApply = "btnUserApply";
}

public class PageObject
{
    [FindsBy(How = How.Id, Using = Locators.btnUserApply)]
    public Button ApplyButton { get; set; }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM