2

In webdriver, with c#, you can define a html element using this:

//Textfields        
public static IWebElement userFieldElement 
{
   get {return Configuration.driver.FindElement(By.XPath(".//input[@name='USER']"));}
}   

Is it there an abbreviated way of defining the same? I have tried:

public static IWebElement passwordFiedfElement = Configuration.driver.FindElement(By.XPath(".//input[@name='USER']"));

But it is invalid because webdriver tries to find all the elements defined in this way if the class that contains them is called for any reason. The first method works, anyway.

Saifur
  • 16,081
  • 6
  • 49
  • 73
pfernandez
  • 303
  • 2
  • 12

1 Answers1

2

Another possible way is probably to use the FindsBy class

[FindsBy(How = How.XPath, Using = ".//input[@name='USER']")]
public IWebElement userFieldElement { get; set; }
Saifur
  • 16,081
  • 6
  • 49
  • 73