0

I am building some tests for a desktop application using the win app driver. Everything is fine but can't use the page factory model I've used before in web applications. The problem is if an element hasn't finished loading then any kind of wait doesn't run before the element is accessed. As soon as I call the wait it fails

Waits.WaitForDisplayedEnabled(Scan.BarcodeField, Driver, 3);

... as soon as this is accessed (and before it can run) the code jumps to the element in the "page" I've setup and says it can't be found. I know the element can be found when debugging so the element locator is fine. Is there a better way to setup elements in pages without being able to use the Page Factory model? The Page factory would seem to not immediately try and access the element which is why it worked so well. The following is how I'm setting up the element...

public WindowsElement BarcodeField => Driver.FindElementByXPath("//*[@Name='Barcode' and @ClassName='TextBlock']");
alex
  • 135
  • 3
  • 17
  • You should store the locator in a string and pass it to wait, instead of passing the WebElement. In your case, you are invoking `FindElement` first and THEN pass it to wait. That implies the element already exists. – Fenio Jun 18 '19 at 11:52
  • Agree with @Fenio . Another way is you can add thread sleep time before Waits.WaitForDisplayedEnabled but not recommended. – Devdun Jun 18 '19 at 12:55
  • Thanks both. Updated with changes and working fine. – alex Jun 18 '19 at 15:22

1 Answers1

0

Thanks guys. Needed a change here and there but am now setting the elements as follows...

public By BarcodeField => By.XPath("//*[@Name='Barcode' and @ClassName='TextBlock']");

...and the waits now use By instead of WindowsElement

alex
  • 135
  • 3
  • 17