webdriver html元素的缩写定义



在webdriver中,使用c#,你可以这样定义一个html元素:

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

是否有一种简化的方式来定义相同的?我试过了:

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

但是它是无效的,因为webdriver试图找到所有以这种方式定义的元素,如果包含它们的类因任何原因被调用。无论如何,第一种方法是有效的。

另一种可能的方法是使用FindsBy类

[FindsBy(How = How.XPath, Using = ".//input[@name='USER']")]
public IWebElement userFieldElement { get; set; }

最新更新