WinAppDriver icon indicating copy to clipboard operation
WinAppDriver copied to clipboard

I request an example sample of Java.

Open YeonwooJeong opened this issue 7 years ago • 5 comments

I request an example sample of Java.

I'd especially like to know a sample of Java examples that to switch each other applications.

There is a dearth of examples in Java.

Have you will update plan for java

YeonwooJeong avatar Nov 01 '19 04:11 YeonwooJeong

We're more than happy to take any community submissions here and merge them in. If anyone wants to contribute, please submit a PR!

hassanuz avatar Nov 01 '19 21:11 hassanuz

Hi @YeonwooJeong I have worked with Java and can help you with example. Please provide a little more explanation for your requirement

birarroshan avatar Nov 08 '19 06:11 birarroshan

@birarroshan hi I have an issue related to this. https://github.com/microsoft/WinAppDriver/issues/886 https://github.com/microsoft/WinAppDriver/issues/870

Thanks for your answer. can you help me?

YeonwooJeong avatar Nov 08 '19 07:11 YeonwooJeong

@YeonwooJeong Here's the Java example

private static WindowsDriver desktopSession=null; private static WindowsDriver edgeSession=null; //switch to desktop/root Session appCapabilities.setCapability("app", "Root"); desktopSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), appCapabilities);

//getting the native window handle of app to switch to String NativeWindowHandle=desktopSession.findElementByName("xyz"); //name of the app you wish to switch to int natWinHandleInt = Integer.parseInt(NativeWindowHandle); String natWinHandleStr = Integer.toHexString(natWinHandleInt); String handle="0x"+natWinHandleStr;

//switching to different app appCapabilities.setCapability("appTopLevelWindow", handle); edgeSession=new WindowsDriver(new URL("http://127.0.0.1:4723"), appCapabilities);

//do stuff with the new app

Hope that helps!!

shilpamalhotra-git avatar Aug 27 '21 07:08 shilpamalhotra-git

@YeonwooJeong Here's the Java example

private static WindowsDriver desktopSession=null; private static WindowsDriver edgeSession=null; //switch to desktop/root Session appCapabilities.setCapability("app", "Root"); desktopSession = new WindowsDriver(new URL("http://127.0.0.1:4723"), appCapabilities);

//getting the native window handle of app to switch to String NativeWindowHandle=desktopSession.findElementByName("xyz"); //name of the app you wish to switch to int natWinHandleInt = Integer.parseInt(NativeWindowHandle); String natWinHandleStr = Integer.toHexString(natWinHandleInt); String handle="0x"+natWinHandleStr;

//switching to different app appCapabilities.setCapability("appTopLevelWindow", handle); edgeSession=new WindowsDriver(new URL("http://127.0.0.1:4723"), appCapabilities);

//do stuff with the new app

Hope that helps!!

I just saw your answer. But I still haven't solved the problem.

Specific explanations are needed for each code. I don't even know why there is an error in the variable. can you check my video?

https://user-images.githubusercontent.com/8816386/139401545-5efbc455-1af9-41e4-8bf5-49787ea592e8.mp4

YeonwooJeong avatar Oct 29 '21 08:10 YeonwooJeong