webdriver页面对象中的非静态字段需要对象引用

时间:2013-11-10 15:04:36

标签: c# webdriver

我想初始化一些属性而不是使用它来使用C#和webdriver页面对象在页面中查找元素(在java中,以下代码正在工作),但是显示以下错误使用属性 containerID

  

非静态字段需要对象引用。

这是我的代码:

class DescriptionPopUp
{
        public string containerID { get; private set; }

        [FindsBy(How = How.XPath, Using = String.Format("//div[@id='{0}']//div[@class='close-Button']", containerID))]
        public IWebElement CloseButton { get; set; } 

        public DescriptionPopUp(string containerID)
        {
            this.containerID = containerID;
        }
}

有没有一种聪明的方法来处理这个问题?

1 个答案:

答案 0 :(得分:1)

不,您不能将变量分配给这样的属性。 .NET中的属性在编译时进行评估,在编译时,无法可靠地确定实例变量值。你需要提出另一种解决方案。这是语言的限制,而不是WebDriver。