简体   繁体   English

使用资源文件c#Selenium的FindsBy属性

[英]FindsBy attribute with resource file c# Selenium

Using PageObject pattern in selenium and i would like to put all the locators in a resource file. 在selenium中使用PageObject模式,我想将所有定位器放在资源文件中。

wondering if possible to use a FindsBy Attribute with resource file 想知道是否可以在资源文件中使用FindsBy属性

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

becomes as below which gives an error and cannot be done 如下所示会产生错误而无法完成

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

FindsBy is also sealed so cannot inherit . FindsBy也是密封的,所以不能继承。

Any suggestions? 有什么建议么?

It isn't possible. 这是不可能的。 FindsBy annotation receives const (evaluated in compilation) string as the Using parameter. FindsBy注释接收const(在编译时评估)字符串作为Using参数。 Data from resource file is evaluated in run time. 资源文件中的数据在运行时进行评估。

You could create another class to hold all the locators 您可以创建另一个类来保存所有定位器

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.

相关问题 如何在Selenium C#中使用PageFactory / FindsBy初始化SelectElements? - How to initialize SelectElements while using PageFactory / FindsBy in Selenium C#? Selenium(C#)中的FindsBy-PageObjectPattern jQuery UI网站问题 - FindsBy-PageObjectPattern in Selenium (C#) jQuery UI websites issues 有没有办法在 Selenium 的 C# 端口中为 WebDriverWait 使用 FindsBy 注释? - Is there a way to use the FindsBy annotation for WebDriverWait in the C# port of Selenium? Selenium FindsBy属性抛出编译器错误 - Selenium FindsBy attribute throws compiler error 硒在派生类中重写FindsBy属性 - Selenium override FindsBy attribute in derived class 资源文件中的C#属性文本? - C# attribute text from resource file? C#Webdriver FindsBy-用于剑道元素 - C# Webdriver FindsBy - for Kendo elements 使用PageObjects的C#Selenium Webdriver:无法使用FindsBy定位对象; 可以使用FindElement查找相同的对象 - C# Selenium Webdriver using PageObjects: Unable to locate object using FindsBy; Can find same object using FindElement C#Webdriver FindsBy-在页面对象框架类的ID变量中将具有相似文本的FindsBy语句组合 - C# Webdriver FindsBy - Combining FindsBy Statements with similar text in ID variable in a Page Object Framework Class 将变量传递给FindsBy硒 - Passing variable to FindsBy selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM