简体   繁体   中英

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.

wondering if possible to use a FindsBy Attribute with resource file

[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 .

Any suggestions?

It isn't possible. FindsBy annotation receives const (evaluated in compilation) string as the Using parameter. 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; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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