Can't switch from application to desktop
See original GitHub issueHi.
When I try to switch from an application window to the desktop window, I get the following error:
OpenQA.Selenium.WebDriverException: 10010 is not a top level window handle
[TestClass]
public class UnitTest1
{
Uri winAppDriverUri = new Uri("http://127.0.0.1:4723/wd/hub");
Process driverProcess = null;
[TestInitialize]
public void TestInitialize()
{
driverProcess = LaunchDriver(winAppDriverUri);
}
[TestCleanup]
public void TestCleanup()
{
driverProcess?.Close();
}
[TestMethod]
public void AppRoot() // this works and outputs the same window handle as the next test method
{
AppiumOptions options = new AppiumOptions();
options.PlatformName = "Windows";
options.AddAdditionalCapability("platformVersion", "1.0");
options.AddAdditionalCapability("app", "Root");
WindowsDriver<WindowsElement> driver = new WindowsDriver<WindowsElement>(winAppDriverUri, options);
Console.WriteLine(driver.CurrentWindowHandle);
}
[TestMethod]
public void SwitchToDesktop() // this fails with WebDriverException: 10010 is not a top level window handle
{
AppiumOptions options = new AppiumOptions();
options.PlatformName = "Windows";
options.AddAdditionalCapability("platformVersion", "1.0");
options.AddAdditionalCapability("app", @"C:\Windows\System32\notepad.exe");
WindowsDriver<WindowsElement> driver = new WindowsDriver<WindowsElement>(winAppDriverUri, options);
IntPtr desktopWindowHandle = GetDesktopWindow();
string desktopWindowHandleAsHex = desktopWindowHandle.ToInt32().ToString("x");
Console.WriteLine(desktopWindowHandleAsHex);
driver.SwitchTo().Window(desktopWindowHandleAsHex);
}
private Process LaunchDriver(Uri uri)
{
string exeFilePath = @"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe";
string commandLineArguments = $"{uri.Host} {uri.Port}{uri.PathAndQuery}";
ProcessStartInfo processStartInfo = new ProcessStartInfo(
exeFilePath,
commandLineArguments)
{
CreateNoWindow = true,
UseShellExecute = false
};
Process process = new Process()
{
StartInfo = processStartInfo
};
process.Start();
return process;
}
[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
private static extern IntPtr GetDesktopWindow();
}
Any ideas?
Thank you.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Can't switch between application windows
If I have multiple application windows open such as word, excel and chrome I cannot switch between them unless I minimise the application...
Read more >Cannot switch between Programs by clicking on Taskbar ...
Open Task Manager using ALT+CTRL+DEL, find explorer.exe in the list of programs, right-click on it, and select Restart. 2] Change Foreground ...
Read more >Windows 10 Alt+Tab can't switch to desktop
To get Desktop in the Taskbar, right click the Task bar and select Toolbars → then click Desktop to add it to the...
Read more >FIX: Can't switch between programs (Alt+Tab) in Windows ...
Can't switch between your app or programs in Windows 10 or Windows 8.1 with your ALT + TAB buttons? Here's how to fix...
Read more >Move an Application Window From Off-screen Back to Your ...
Hold down the Shift key, then right-click on the appropriate application icon in the Windows taskbar. On the resulting pop-up, select the Move...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just found the solution of this problem. I’m just disgusted after knowing how easy the solution is!!!
I posted it on stackOverflow. You can check it out here
Why they did not bother to answer the question Neh18 asked! Really disappointed for that. The whole internet is asking for the same problem that they are not able to switch to a top level window. But none, literally none is asking how to switch to a NonTopLevelWindow. I’m stuck on this issue and miraculously there seems to be no solution. Awesome!
BTW, Neh18, TheHlee did you guys find any solution for this problem?