C# 使用WinApp驱动程序在桌面任务栏中打开应用程序时如何切换应用程序

C# 使用WinApp驱动程序在桌面任务栏中打开应用程序时如何切换应用程序,c#,appium,desktop,winappdriver,C#,Appium,Desktop,Winappdriver,我正在使用Winapp驱动程序、appium和c#实现桌面应用程序的自动化。 我的任务是:点击打开excel工作表的按钮,它现在显示在桌面的任务栏上。现在我想从桌面应用程序切换到excel工作表 对于同样的问题,我无法找到一个单一的解决方案。我们将不胜感激 1.)尝试通过以下方式获取WindowHandles() 2.)如果集合仅包含一个句柄,则您需要为excel创建新的桌面会话,您可以通过以下方式执行相同操作: //get a root driver //all the opened app

我正在使用Winapp驱动程序、appium和c#实现桌面应用程序的自动化。 我的任务是:点击打开excel工作表的按钮,它现在显示在桌面的任务栏上。现在我想从桌面应用程序切换到excel工作表

对于同样的问题,我无法找到一个单一的解决方案。我们将不胜感激

1.)尝试通过以下方式获取WindowHandles()

2.)如果集合仅包含一个句柄,则您需要为excel创建新的桌面会话,您可以通过以下方式执行相同操作:

//get a root driver 
//all the opened application will be children of this root driver
//get the expected child driver

 DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability("app", "Root");
        WindowsDriver rootDriver = new WindowsDriver(new URL("http://127.0.0.1:4723"), cap);


 WebElement ele = d.findElementByName("Book - Excel"); //Pass the header or title of the excel opened
        String toplevel = ele.getAttribute("NativeWindowHandle");
        int x  = (Integer.parseInt(toplevel));
        toplevel = Integer.toHexString(x);


DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability("appTopLevelWindow", toplevel);
        WindowsDriver childdriver = new WindowsDriver(new URL("http://127.0.0.1:4723"), cap);
childDriver是指向Excel应用程序的驱动程序

希望这有帮助。

遵循它可能会有所帮助
driver.switchTo.window(windowHandleOfExcel);
//get a root driver 
//all the opened application will be children of this root driver
//get the expected child driver

 DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability("app", "Root");
        WindowsDriver rootDriver = new WindowsDriver(new URL("http://127.0.0.1:4723"), cap);


 WebElement ele = d.findElementByName("Book - Excel"); //Pass the header or title of the excel opened
        String toplevel = ele.getAttribute("NativeWindowHandle");
        int x  = (Integer.parseInt(toplevel));
        toplevel = Integer.toHexString(x);


DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability("appTopLevelWindow", toplevel);
        WindowsDriver childdriver = new WindowsDriver(new URL("http://127.0.0.1:4723"), cap);