[英]how to switch application winappdriver in java
I want to switch File Explorer and Chrome browser.我想切换文件资源管理器和 Chrome 浏览器。
how to switch application?如何切换应用程序?
in my code在我的代码中
@BeforeClass
public static void setup() {
try {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("app", "C:\\Windows\\explorer.exe");
ExplorerSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), capabilities);
ExplorerSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
actions = new Actions(ExplorerSession);
modules = new Modules(ExplorerSession);}
can I generate new Session?我可以生成新的 Session 吗?
I reference next link我参考下一个链接
https://github.com/Microsoft/WinAppDriver/tree/v1.0#creating-a-desktop-session https://github.com/microsoft/WinAppDriver/blob/35a659232060a6e436cbb8393ae9a09bab12bc89/Samples/C%23/StickyNotesTest/StickyNotesSession.cs https://github.com/Microsoft/WinAppDriver/tree/v1.0#creating-a-desktop-session https://github.com/microsoft/WinAppDriver/blob/35a659232060a6e436cbb8393ae9a09bab12bc89/Samples/C%23/StickyNotesTest/StickyNotesSession 。CS
but I could't resolve this problem但我无法解决这个问题
Not enough information in Java. Java 中没有足够的信息。
No API documents found, either.也没有找到 API 文档。 Please help me.
请帮我。
You will need different objects of ChromeDriver and WindowsDriver.您将需要不同的 ChromeDriver 和 WindowsDriver 对象。 The ChromeDriver object will operate using Selenium, the WindowsDriver object will use the WinAppDriver.
ChromeDriver object 将使用 Selenium 运行,WindowsDriver object 将使用 WinAppDriver。 I hope this helps.
我希望这有帮助。
I found the solution to this problem by using the info in the first link in the OP to get the NativeWindowHandle and use that to bring focus to each application.我通过使用 OP 中第一个链接中的信息来获取 NativeWindowHandle 并使用它来为每个应用程序带来焦点,从而找到了解决此问题的方法。 I had to append 0x to the front of the Handle returned by my application in order to pass it to the desired capabilities in the next test, but otherwise the instructions in the link worked well for me.
我必须将 append 0x 放在我的应用程序返回的句柄前面,以便在下一次测试中将其传递给所需的功能,但否则链接中的说明对我来说效果很好。
String NativeWindowHandle = driver.findElementByAccessibilityId("ShellForm").getAttribute("NativeWindowHandle");
int natWinHandleInt = Integer.parseInt(NativeWindowHandle);
String natWinHandleStr = Integer.toHexString(natWinHandleInt);
natWinHandle = "0x"+natWinHandleStr;
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.setCapability("appTopLevelWindow", natWinHandle);
driver = new WindowsDriver<WindowsElement> (new URL("http://127.0.0.1:4723"), appCapabilities);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.