简体   繁体   English

如何在java中切换应用程序winappdriver

[英]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.

相关问题 如何使用 WinAppDriver Java 在窗口之间切换焦点 - How to switch focus between windows using WinAppDriver 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? 如何通过Java应用程序在网络之间切换? - How to switch between networks from a Java application? WinAppDriver 如何在不获取 java.lang.ClassCastException 的情况下在 Java 中定义 WindowsElement - WinAppDriver how to define a WindowsElement in Java without getting java.lang.ClassCastException 如何在不为winappdriver创建新会话的情况下为每个测试用例启动测试应用程序 - How to launch application under test for every test case without creating the new session for winappdriver 如何切换java Frames? - How to switch java Frames? 通过应用程序开关使Java工具提示消失 - Making java tooltips disappear with application switch 基于Java的Android应用程序 - >切换到Scala - Java-based Android application -> switch to Scala 我无法在 WinAppDriver 的 Excel 单元格之间移动 Java - I can't move between Excel cells by WinAppDriver by Java 基于 winappdriver 的 java selenium 自动化在一段时间后停止工作 - winappdriver based java selenium automation stops working after some time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM