microsoft / WinAppDriver

Windows Application Driver
MIT License
3.65k stars 1.4k forks source link

Element not found error - the second time a find WindowsElement method is invoked in same test (the first works as a charm) #1381

Open mrs-mowgli opened 3 years ago

mrs-mowgli commented 3 years ago

I have a setup where the test goes from a browser app to a TrayIcon app and back a couple of times. The strange thing is that this has been working for at least 20 test runs until last week. And stopped suddenly without any changes in code that might be involved.

The test run starts in the browser application. A verification is made in the TrayIcon app, where the click on TrayIcon works perfectly. Then the test proceeds, in the TrayIcon app, with some tasks. In the browser app, the tasks will be verified and handled. Then the tests proceed in the TrayIcon app. Now suddenly the click method on the TrayIcon app cannot find the Windows element.

Steps that had been working after click that now fails: Some tasks in the TrayIcon app. Verification in the browser app.

I have done: Upgrade/downgrade/Upgrade WAD, added/and modified the find element method to use XPath instead of Name. With some Console.Writelines it seems like the test runs through the method but is not performing anything.

I have run out of ideas. Anyone out there that has some input.

The output of the test failure is OpenQA.Selenium.WebDriverException: An element could not be located on the page using the given search parameters.

Stack Trace: RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters) AppiumDriver1.Execute(String driverCommandToExecute, Dictionary2 parameters) RemoteWebDriver.FindElement(String mechanism, String value) AppiumDriver1.FindElement(String by, String value) AppiumDriver`1.FindElementByAccessibilityId(String selector)

anunay1 commented 3 years ago

Can you share some code, how are you trying to switch are you creating a root session and then switching to the opened window

mrs-mowgli commented 3 years ago

public static void InitWinDriver() { AppiumOptions appOpt = new AppiumOptions(); appOpt.AddAdditionalCapability("app", TrayIconId); appOpt.AddAdditionalCapability("deviceName", "WindowsPC"); appOpt.AddAdditionalCapability("app", "Root"); InstanceWinDriver = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), appOpt); }

I quit the webdriver session after each test part of the webapp. Not the best way, I know, thought of some kind of switch between the drivers would be a nicer approach, but I did get it to work.

licanhua commented 3 years ago

You can try GetPageSource and Screenshot to see if there is anything abnormal

mrs-mowgli commented 3 years ago

As far as I know, GetPageSource is a WebDriver method. The issue is, calling the method that clicks on the Windows TrayIcon application the second time, in the test run fails. The first time it works perfectly.