-1

I want to init some property once and than to use it to find elements in the page using C# with webdriver page object (in java the following code is working), But the following error is shown for using the property containerID :

An object reference is required for the non-static field.

This is my code:

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;
        }
}

Is there an smart way to handle the problem?

Gabriel kotev
  • 369
  • 3
  • 15

1 Answers1

1

No, you can't assign a variable to an attribute like that. Attributes in .NET are evaluated at compile time, and at compile time, instance variable values cannot be reliably determined. You'll need to come up with another solution. This is a limitation of the language, not of WebDriver.

JimEvans
  • 27,201
  • 7
  • 83
  • 108
  • Is there any way of handling that problem ? The best way I have found is putting the variable inside get method. If I'll create some new class to hold just the properties and use it, will it be a proper solution? – Gabriel kotev Nov 11 '13 at 06:11