gpt4 book ai didi

c# - webdriver html 元素的缩写定义

转载 作者:太空宇宙 更新时间:2023-11-03 10:30:51 25 4
gpt4 key购买 nike

在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com