I am thinking that page factory web elements don't work with fluent wait. I have the following case where I am waiting for the presense of an element and it doesn't seem to work when using page factory web elements
public class HomePage
{
private IWebDriver driver;
[FindsBy(How = How.Id, Using = "submitBtn")]
public IWebElement SubmitBtn { get; private set; }
public HomePage(IWebDriver driver)
{
this.driver = driver;
PageFactory.InitElements(driver, this);
}
}
Test class using Page Factory
public class HomePageTests : BaseTest
{
[Test]
public void SomeTest()
{
base.Driver = base.InitDriver();
HomePage homePage = new(Driver);
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30))
{
PollingInterval = TimeSpan.FromSeconds(5),
};
wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
wait.Until(ExpectedConditions.ElementToBeClickable(homePage.SubmitBtn()));
homePage.SubmitBtn.Click();
}
}
Test class using By locator
public class HomePageTests : BaseTest
{
[Test]
public void SomeTest()
{
base.Driver = base.InitDriver();
HomePage homePage = new(Driver);
WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30))
{
PollingInterval = TimeSpan.FromSeconds(5),
};
wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
var submitBtn = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("submitBtn"));
submitBtn.Click();
}
}
It seems to work on not using the page factory web element but passing a locator. I've been testing it consistenty for a period of time and wondering if page factory web elements are initalized different to using by locator (I am aware of the lazy load but could that be part of the reason?).
EDIT The exception I get is NoSuchElementException