WinAppDriver - unable to switch window and window handle list is empty
Hello Team, WinAppDriver is not recognizing the controls on the desktop application. however when i inspect the element using inspect.exe, inspect is able to recognize the controls in tree view.
additional exception details
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=An element could not be located on the page using the given search parameters.
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters)
at OpenQA.Selenium.Appium.AppiumDriver1.Execute(String driverCommandToExecute, Dictionary2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByName(String name)
at OpenQA.Selenium.By.<>c__DisplayClassa.<Name>b__8(ISearchContext context)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
at OpenQA.Selenium.Appium.AppiumDriver1.FindElement(By by)
at UnitTestProject1.UnitTest1.TestMethod1() in c:\Users\k_agrawal\Documents\Visual Studio 2013\Projects\UnitTestProject1\UnitTestProject1\UnitTest1.cs:line 40
InnerException:
Hi @kapi79,
Could you also please share what the WinAppDriver.exe console logs are outputting?
Thank you
The Actual issue is My Application opens up another Window post button click. and when i am trying to switch to the new window its not doing so. hence not able to find the controls however below is console log POST /session/0F539C3F-75CE-44E9-9EE1-E9921981CB80/element HTTP/1.1 Accept: application/json, image/png Content-Length: 38 Content-Type: application/json;charset=utf-8 Host: 127.0.0.1:4723
{"using":"name","value":"_tabControl"} HTTP/1.1 404 Not Found Content-Length: 139 Content-Type: application/json
{"status":7,"value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters."}}
I tried two methods 1. creating the desktop Session obejct and get windowhandels, 2. finding the window handles from the same session object which i used to launch the application but in both cases the handles are not found. case 1- count returned =0 case threw an exception: WindowHandles = '((OpenQA.Selenium.Remote.RemoteWebDriver)(calSession)).WindowHandles' threw an exception of type 'OpenQA.Selenium.WebDriverException'
tried to switchto().window("MainWindow") - unknown exception at remote end - An exception of type 'System.InvalidOperationException' occurred in WebDriver.dll but was not handled in user code
Additional information: An unknown error occurred in the remote end while processing the command.
Console Log : POST /session/2F4AC82F-AC34-4ACC-B176-8DEDFF48C49D/window HTTP/1.1 Accept: application/json, image/png Content-Length: 44 Content-Type: application/json;charset=utf-8 Host: 127.0.0.1:4723
{"name":"Domino Express (AMER-Domino SIT4)"} HTTP/1.1 500 Internal Error Content-Length: 133 Content-Type: application/json
{"status":13,"value":{"error":"unknown error","message":"An unknown error occurred in the remote end while processing the command."}}
@kapi79, I did find a solution to switching to different apps
taskbarButtonForRdpXpath = "//ToolBar[@ClassName='MSTaskListWClass']/MenuItem[contains(@Name,'Remote Desktop Connection')]"
taskbarRdpThumbnailXpath = "//List[@ClassName='TaskListThumbnailWnd']//ListItem[contains(@Name,'%s')]"
I use the taskbarButtonForRdpXpath to find the taskbar button and click it. that brings up the multiple windows for that application.
I then use the taskbarRdpThumbnailXpath to find the application I want by titlebar name.
The WinAppDriver Window Handle is still broken, but this may be enough to get you through your current issue.
ok let me try the same
An exception of type 'System.InvalidOperationException' occurred in WebDriver.dll but was not handled in user code
Additional information: An element could not be located on the page using the given search parameters.
i used following code string taskbarButtonForRdpXpath = "//ToolBar[@ClassName='MSTaskListWClass']/MenuItem[contains(@Name,'Domino Express (AMER-Domino SIT4)')]"; string taskbarRdpThumbnailXpath = "//List[@ClassName='TaskListThumbnailWnd']//ListItem[contains(@Name,'%s')]"; calSession.FindElementByXPath(taskbarButtonForRdpXpath);
I think your code may have several issues. But the first thing to be sure you understand is what the UI structure looks like,
If you use
Console.WriteLine(calSession.GetPageSource());
you can see the structure of the UI to verify your xpath is correct.
By looking at the xpath you post, (and presuming you are using C# and not Java), you may have a few changes to make
string taskbarButtonForDominoXpath = "//ToolBar[@ClassName='MSTaskListWClass']/MenuItem[contains(@Name,'Domino Express')]";
calSession.FindElementByXPath(taskbarButtonForDominoXpath);
(Note the following changes 1) capital 'N' in 'Name' 2) the shortened name to 'Domino Express' in the 'contains' clause and 3) variable name change to indicate that this is an xpath for Domino instead of RDP)
If this doesn't work for you, attach the output from the Console.WriteLine above (preferrably formatted).
Additionally, posting a full code sample with full stacktrace would be useful as well.
Good Luck!
Hello Robert,
how to switch session control from windows desktop application to chrome url in winappdriver?? my application is windows desktop and it has an option to click on links to open browser url but i am not able to move my control to that open browser, do you have any idea to do it
Sorry for the late reply. Unfortunately, I don't have any information to help with this issue. Good luck in finding your solution!
You can try this code for your Switch window.. var currentWindowHandle = driver.CurrentWindowHandle; Thread.Sleep(TimeSpan.FromSeconds(10)); var allWindowHandles2 = driver.WindowHandles; driver.SwitchTo().Window(allWindowHandles2[0]);