1

有没有人使用 C# 和 Selenium 的 PageFactory 知道如何实现 How.Custom 定位器?我在网上搜索了高低都无济于事。所有的例子都在java中,甚至那些似乎也相距甚远。

4

1 回答 1

3

创建一个类,如:

public class NgByModelFinder : By
{
    public NgByModelFinder(string locator)
    {
        FindElementMethod = (ISearchContext context) => context.FindElement(NgBy.Model(locator));
    }
}

然后将 FindsBy 属性附加到您的 web 元素中,例如:

[FindsBy(How = How.Custom, Using = "value for locator", CustomFinderType = typeof(NgByModelFinder))]
protected IWebElement TestDiv { get; set; }

我希望以上内容对您有所帮助。

于 2016-06-15T06:34:16.300 回答