简体   繁体   English

如何使用 WinAppDriver Java 在窗口之间切换焦点

[英]How to switch focus between windows using WinAppDriver Java

I am new to windows automation using win app driver.我是使用 win 应用程序驱动程序的 Windows 自动化新手。 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.我们的应用程序是使用 chromium 浏览器开发的,我们正在使用 win app diver 进行自动化,因为我们尝试打开的主应用程序是基于 Windows 的。 When I click on Ok button opens another window(Window B).当我单击确定按钮时,会打开另一个窗口(窗口 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.我有 2 个窗口打开窗口 1 和窗口 2。我需要在两个窗口上执行操作,因为我需要在两个窗口之间转移焦点。 When I use getwindowhandles() method I am getting number of windows opened as 1. How can I switch between windows using winapp driver.当我使用 getwindowhandles() 方法时,我打开的窗口数为 1。如何使用 winapp 驱动程序在窗口之间切换。 Appreciate your help.感谢你的帮助。 Thanks谢谢

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.但是,我不希望这适用于您的情况,因为您打开的窗口数量为 1,这意味着没有第二个窗口可以切换到。 So in your case you can use root session in order to attach to your window:因此,在您的情况下,您可以使用根会话来附加到您的窗口:

 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 https://github.com/microsoft/WinAppDriver/issues/978
OpenQA.Selenium.WebDriverException: [windowHandle] is not a top level window handle solution 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());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在java中切换应用程序winappdriver - how to switch application winappdriver in java 如何使用Selenium java在浏览器中的两个窗口之间切换 - How to switch between two windows in browser using Selenium java 如何使用带有Java的Selenium WebDriver在Chrome中的Windows之间切换? - How to switch between windows in Chrome using Selenium WebDriver with Java? 如何使用Java在Runnng Windows应用程序之间切换? - How to switch between runnng windows applications using java? URL &#39;/session&#39; 未映射到有效资源 | 如何使用 winAppDriver / windows 应用程序驱动程序使用 java 运行桌面应用程序测试? - The URL '/session' did not map to a valid resource | How to run desktop application test using winAppDriver / windows application driver using java? 如何使用eclipse在python和java之间切换 - How to switch between python and java using eclipse 如何在 java 中使用 selenium 在两个或多个 chrome 浏览器 windows(不是标签)之间切换? - How to switch between two or mutlple chrome browser windows (Not tabs) using selenium in java? 使用Selenium Java在浏览器中的两个窗口之间切换 - switch between two windows in browser using Selenium java 如何在 Java 中不同 webdriver 打开的 chrome windows 之间切换? - How to switch between chrome windows opened by different webdriver in Java? 在Windows中安装和切换java 7和java 8 - install and switch between java 7 and java 8 in windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM