由于PageFactory在最新的C#硒版本中已弃用,因此我试图重新编写现有的PageObject,如下面的代码片段所示。除了元素尚未加载之外,其他所有操作都像以前一样。在与它们进行交互之前,我已经编写了ExplicitWaitConditions,但是在到达ExplicitWaitConditions之前,我在FindElement(By.Id(“ email”))本身上遇到了NoSuchElementException异常。当我使用PageFactory时,它工作正常。非常感谢您的帮助和建议
public LoginPage(IWebDriver _driver)
{
driver = _driver;
//if (driver != null)
//{
// PageFactory.InitElements(driver, this);
//}
}
//[FindsBy(How = How.Id, Using = "email")]
//public IWebElement txtUserName { get; set; }
//No such element exception is thrown by below line
public IWebElement txtUserName => driver.FindElement(By.Id("email"));
尝试如下添加“ this”
private IWebDriver _driver;
public LoginPage(IWebDriver _driver)
{
this._driver = _driver;
}