gpt4 book ai didi

How to switch focus between windows using WinAppDriver Java(如何使用WinAppDriver Java在窗口之间切换焦点)

转载 作者:bug小助手 更新时间:2023-10-25 11:14:42 34 4
gpt4 key购买 nike



I am new to windows automation using win app driver.
Our application is developed with chromium browser and we are using win app diver to automate since the main app we are trying to open is windows based.
When I click on Ok button opens another window(Window B). I have 2 windows opened window 1 and window 2. I need to perform actions on both the windows for that I need to shift the focus between two windows. When I use getwindowhandles() method I am getting number of windows opened as 1.
How can I switch between windows using winapp driver.
Appreciate your help.
Thanks

我对使用Win应用程序驱动程序的Windows自动化是新手。我们的应用程序是用Chrome浏览器开发的,我们使用Win应用程序潜水器来自动化,因为我们试图打开的主要应用程序是基于Windows的。当我点击OK按钮时,会打开另一个窗口(窗口B)。我有2个窗口打开了窗口1和窗口2。我需要在这两个窗口上执行操作,我需要在两个窗口之间切换焦点。当我使用getwindowhandles()方法时,我得到的打开窗口数为1。如何使用winapp驱动程序在窗口之间切换。感谢你的帮助。谢谢


更多回答
优秀答案推荐

I am using in my code:

我在我的代码中使用:


 this.driver.SwitchTo().Window(this.driver.WindowHandles[0]);

However, I do not expect this to work in your case, as your number of open windows is 1, than means that there is no second window to switch to.
So in your case you can use root session in order to attach to your window:

但是,我认为这在您的情况下不会起作用,因为您打开的窗口数量是1,这意味着没有第二个窗口可供切换。因此,在您的情况下,可以使用根会话来附加到您的窗口:


 AppiumOptions rootSessionOptions = new AppiumOptions();
rootSessionOptions.AddAdditionalCapability("app", "Root");
rootSessionOptions.AddAdditionalCapability("deviceName", "WindowsPC");
_driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), rootSessionOptions);
_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

var VSWindow = _driver.FindElementByName("Your project name without .csproj - Microsoft Visual Studio");
var VSTopLevelWindowHandle = VSWindow.GetAttribute("NativeWindowHandle");
VSTopLevelWindowHandle = (int.Parse(VSTopLevelWindowHandle)).ToString("x");

AppiumOptions VisualStudioSessionOptions = new AppiumOptions();
VisualStudioSessionOptions.AddAdditionalCapability("appTopLevelWindow", VSTopLevelWindowHandle);
_driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), VisualStudioSessionOptions);

_driver.SwitchTo().Window(_driver.WindowHandles[0]);

Reference:

https://github.com/microsoft/WinAppDriver/issues/978

OpenQA.Selenium.WebDriverException: [windowHandle] is not a top level window handle solution

参考:https://github.com/microsoft/WinAppDriver/issues/978 OpenQA.Selenium.WebDriverException:[WindowHandle]不是顶级窗口句柄解决方案



This code works for me (windows automation using win app driver) with C#
//Switch to the next window in desktop application:

此代码适用于我(使用Win应用程序驱动的Windows自动化),使用C#//切换到桌面应用程序中的下一个窗口:


 IList<string> toWindowHandles = new List<string>(_driver.WindowHandles);
Thread.Sleep(6000);

_driver.SwitchTo().Window(_driver.WindowHandles[0]);

With Java:

使用Java:


    Thread.sleep(5000);
//Switch to the next window in desktop application:
Set<String> windowHandles = driver.getWindowHandles();
driver.switchTo().window(windowHandles.iterator().next());

更多回答

I am able to switch between the windows. Thank you for the help.

我可以在窗口之间切换。谢谢你的帮助。

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com