【发布时间】:2019-10-15 13:28:58
【问题描述】:
由于 PageFactory 在 C# 的最新 selenium 版本中已被弃用,我正在尝试重写我现有的 PageObjects,如下面的代码 sn-p 所示。除了尚未加载元素时,一切都像以前一样工作。在与它们交互之前,我已经编写了 ExplicitWaitConditions,但是在它到达 ExplicitWaitConditions 之前,我在 FindElement(By.Id("email")) 本身上得到了 NoSuchElementException。当我使用 PageFactory 时它工作正常。 非常感谢您的帮助和建议
private IWebDriver driver;
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"));
基本上我想了解的是如何在不使用 PageFactory 的情况下实现延迟初始化。因为在访问元素之前就抛出了错误。
【问题讨论】:
标签: c# selenium-webdriver page-factory