microsoft / WinAppDriver

Windows Application Driver
MIT License
3.7k stars 1.41k forks source link

Unable to switch focus to newly opened "LocalizedControlType:menubar" window #1072

Open Devi9352 opened 4 years ago

Devi9352 commented 4 years ago

I am creating POC for WinAppDriver using Java. Within my application, after i press enter key, another window opens up. But its Localized ControlType is "menubar" and Not "Window" Whose parent is Desktop Since its Localized ControlType is not shown as window, i am unable to switch to that window using getWindowHandles() method Hence i am not able to identify any element within that Menubar window. Could someone help me to resolve this issue?

I get this xpath using UIrRecorder tool: "/Pane[@ClassName='#32769'][@Name='Desktop']/MenuBar[@Name='NB Indexing'][@AutomationId='NBIndexingView']"

Thanks in Advance

VijayHugar commented 4 years ago

Try by creating desktop session and identify the menu bar.

On Sat 22 Feb, 2020, 12:13 AM Devi9352, notifications@github.com wrote:

I am creating POC for WinAppDriver using Java. Within my application, after i press enter key, another window opens up. But its Localized ControlType is "menubar" and Not "Window" Whose parent is Desktop Since its Localized ControlType is not shown as window, i am unable to switch to that window using getWindowHandles() method Hence i am not able to identify any element within that Menubar window. Could someone help me to resolve this issue?

I get this xpath using UIrRecorder tool: "/Pane[@ClassName https://github.com/ClassName='#32769'][@name https://github.com/name='Desktop']/MenuBar[@name https://github.com/name='NB Indexing'][@AutomationId='NBIndexingView']"

Thanks in Advance

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/microsoft/WinAppDriver/issues/1072?email_source=notifications&email_token=AKZQ6JOHPEFP3W7G3A5LT2DREAOFPA5CNFSM4KZIJDR2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IPMCYRA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKZQ6JNY4SQ2XK3ZNCWTF2DREAOFPANCNFSM4KZIJDRQ .

Devi9352 commented 4 years ago

Thanks for the reply. Below mentioned code starts my app:

appCapabilities.setCapability("app", SERVICENAME); appCapabilities.setCapability("deviceName", "WindowsPC"); windowsDriver = new WindowsDriver(new URL("http://127.0.0.1:4723/"), appCapabilities);

I believe I need to set capability like this appCapabilities.setCapabilities(“app”,”Root”) to create a desktop session.

In that case, my app is not getting opened since capability is set at Root level.

Correct me if I am wrong and Kindly help me to resolve this issue.

Appreciate your help.

Thanks in Advance.

From: VijayHugar notifications@github.com Sent: Saturday, February 22, 2020 4:18 AM To: microsoft/WinAppDriver WinAppDriver@noreply.github.com Cc: Murukesan, Chitradevi Chitradevi.Murukesan@PacificLife.com; Author author@noreply.github.com Subject: Re: [microsoft/WinAppDriver] Unable to switch focus to newly opened "LocalizedControlType:menubar" window (#1072)

[External Email]

Try by creating desktop session and identify the menu bar.

On Sat 22 Feb, 2020, 12:13 AM Devi9352, notifications@github.com wrote:

I am creating POC for WinAppDriver using Java. Within my application, after i press enter key, another window opens up. But its Localized ControlType is "menubar" and Not "Window" Whose parent is Desktop Since its Localized ControlType is not shown as window, i am unable to switch to that window using getWindowHandles() method Hence i am not able to identify any element within that Menubar window. Could someone help me to resolve this issue?

I get this xpath using UIrRecorder tool: "/Pane[@ClassName https://github.com/ClassName='#32769'][@name https://github.com/name='Desktop']/MenuBar[@name https://github.com/name='NB Indexing'][@AutomationId='NBIndexingView']"

Thanks in Advance

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/microsoft/WinAppDriver/issues/1072?email_source=notifications&email_token=AKZQ6JOHPEFP3W7G3A5LT2DREAOFPA5CNFSM4KZIJDR2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IPMCYRA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKZQ6JNY4SQ2XK3ZNCWTF2DREAOFPANCNFSM4KZIJDRQ .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/microsoft/WinAppDriver/issues/1072?email_source=notifications&email_token=AOT4FEXALBEGM6PQRZKRKTTREEJY3A5CNFSM4KZIJDR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMU67BY#issuecomment-589950855, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOT4FEX377MCZZHTOZHLV4LREEJY3ANCNFSM4KZIJDRQ.

============================================================================== The information in this e-mail and any attachments are for the sole use of the intended recipient and may contain privileged or confidential information. Delivery to other than the intended recipient shall not be deemed to waive any privilege. Any unauthorized use, disclosure, copying or distribution of this message or attachment is strictly prohibited. If you believe that you have received this e-mail in error, please contact the sender immediately and delete the e-mail and all of its attachments. ==============================================================================

VijayHugar commented 4 years ago

@Devi9352 Here is the scenario that you should try. 1)Create session for working with your application ( Your First logic for launching the app should be enough) - Whatever controls comes under your application tree, should interact with this session only and you should be able to interact with elements under it.

2) In order to interact with other windows which do not falls under your application tree, you should create one more session ( you may name it as DesktopSession) to interact with it.

Here is the code for creating desktop session ....................................................................................................................................................................................................... public static void CreateDesktopSession() { DesiredCapabilities desktopCapabilities = new DesiredCapabilities(); desktopCapabilities.SetCapability("app", "Root"); desktopSession = new WindowsDriver(new Uri("http://127.0.0.1:4723"), desktopCapabilities);

        var ShellWindow = desktopSession.FindElementByClassName("#32770"); // This is class name of my window which appears under Desktop tree.
            var TopLevelWindowHandle = ShellWindow.GetAttribute("NativeWindowHandle");
            TopLevelWindowHandle = (int.Parse(TopLevelWindowHandle)).ToString("x");

            //Attach it to session
            DesiredCapabilities appcapabilities = new DesiredCapabilities();
            appcapabilities.SetCapability("appTopLevelWindow", TopLevelWindowHandle);
            session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appcapabilities);

        }

.......................................................................................................................................................................................................

Devi9352 commented 4 years ago

Thanks for your response. I tried tweaking your code as per my requirement.

//Setting Root capability code

desktopCapabilities = new DesiredCapabilities(); appCapabilities.setCapability("app", "Root"); WindowsDriver desktopSession = new WindowsDriver(new URL("http://127.0.0.1:4723/") ,appCapabilities);

//Finding the menubar window WebElement menuBar = desktopSession.findElementByName("NB Indexing"); String window = menuBar.getAttribute("NativeWindowHandle"); int winHandleInt = Integer.parseInt(window); String winHandleHex = Integer.toHexString(winHandleInt);

DesiredCapabilities cap = new DesiredCapabilities(); appCapabilities.setCapability("appTopLevelWindow",winHandleHex );

WindowsDriver session = new WindowsDriver(new URL(http://127.0.0.1:4723/"), cap);

//Finding an element within the session window WebElement contract = session.findElementByAccessibilityId("tbxPolicy");

The error I am getting is “org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{platformName=Windows}], required capabilities = Capabilities [{}]

I am not sure what url I need to provide here while creating session for that window i.e WindowsDriver session = new WindowsDriver(new URL(http://127.0.0.1:4723/"), cap);

Appreciate your time

Thanks

From: VijayHugar notifications@github.com Sent: Monday, February 24, 2020 12:52 AM To: microsoft/WinAppDriver WinAppDriver@noreply.github.com Cc: Murukesan, Chitradevi Chitradevi.Murukesan@PacificLife.com; Mention mention@noreply.github.com Subject: Re: [microsoft/WinAppDriver] Unable to switch focus to newly opened "LocalizedControlType:menubar" window (#1072)

[External Email]

@Devi9352https://github.com/Devi9352 Here is the scenario that you should try. 1)Create session for working with your application ( Your First logic for launching the app should be enough) - Whatever controls comes under your application tree, should interact with this session only and you should be able to interact with elements under it.

  1. In order to interact with other windows which do not falls under your application tree, you should create one more session ( you may name it as DesktopSession) to interact with it.

Here is the code for creating desktop session

public static void CreateDesktopSession() { DesiredCapabilities desktopCapabilities = new DesiredCapabilities(); desktopCapabilities.SetCapability("app", "Root"); desktopSession = new WindowsDriver(new Uri("http://127.0.0.1:4723"), desktopCapabilities);

    var ShellWindow = desktopSession.FindElementByClassName("#32770"); // This is class name of my window which appears under Desktop tree.

        var TopLevelWindowHandle = ShellWindow.GetAttribute("NativeWindowHandle");

        TopLevelWindowHandle = (int.Parse(TopLevelWindowHandle)).ToString("x");

        //Attach it to session

        DesiredCapabilities appcapabilities = new DesiredCapabilities();

        appcapabilities.SetCapability("appTopLevelWindow", TopLevelWindowHandle);

        session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appcapabilities);

    }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/microsoft/WinAppDriver/issues/1072?email_source=notifications&email_token=AOT4FESU6FKQGBWRL5NHQM3REODCVA5CNFSM4KZIJDR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMXAVPI#issuecomment-590219965, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOT4FES66EBTMVVDOMHTXLTREODCVANCNFSM4KZIJDRQ.

============================================================================== The information in this e-mail and any attachments are for the sole use of the intended recipient and may contain privileged or confidential information. Delivery to other than the intended recipient shall not be deemed to waive any privilege. Any unauthorized use, disclosure, copying or distribution of this message or attachment is strictly prohibited. If you believe that you have received this e-mail in error, please contact the sender immediately and delete the e-mail and all of its attachments. ==============================================================================