在 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; }
关于c# - webdriver html 元素的缩写定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30307373/