microsoft / WinAppDriver

Windows Application Driver
MIT License
3.54k stars 1.39k forks source link

How to access popup window outside of WinAppDriver Appium WinForm in C#? #1984

Open jainchengithub opened 2 months ago

jainchengithub commented 2 months ago

**Hi,

My win app is "Gyro Multi Vendor SPEAR - Version 6.20.14". normal WinAppDriverUIRecorder XML Nodes has my win app included, so I can access.**

<UiTask task="Inspect" x="154" y="619">

<Pane LocalizedControlType="pane" ClassName="#32769" Name="Desktop 1" AutomationId="" x="0" y="0" width="3840" height="2160" Pos=""/>

<Window LocalizedControlType="window" ClassName="WindowsForms10.Window.8.app.0.29531c8_r8_ad1" Name="Gyro Multi Vendor SPEAR - Version 6.20.14  -Development Version" AutomationId="MainControl" x="1155" y="495" width="1530" height="1110" Pos="4"/>

<Window LocalizedControlType="window" ClassName="WindowsForms10.Window.8.app.0.29531c8_r8_ad1" Name="Default Tool Parameters" AutomationId="ParametersDefaultsForm2" x="1304" y="650" width="1233" height="800" Pos=""/>

</UiTask>

But I have a pop up window which does not include my win app name, how to use FindElementByAccessibilityId or FindElementByName etc. to access?

<UiTask task="Inspect" x="374" y="847">

<Pane LocalizedControlType="pane" ClassName="#32769" Name="Desktop 1" AutomationId="" x="0" y="0" width="3840" height="2160" Pos=""/>

<Window LocalizedControlType="dialog" ClassName="#32770" Name="Browse For Folder" AutomationId="" x="1670" y="804" width="978" height="888" Pos="4"/>

</UiTask>

my C# code to declare sessionWinForm:

public class SPEAR_MVTest
{
    static WindowsDriver<WindowsElement> sessionWinForm;
    static private int client_type = 0;

    [ClassInitialize]
    public static void Init(TestContext testContext)
    {
        AppiumOptions dcWinForms = new AppiumOptions();
        dcWinForms.AddAdditionalCapability("app",
        "@C:\Program Files\Gyrodata\Gyro MV SPEAR Dev\Gyro MV Spear.exe");  
        sessionWinForm = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), dcWinForms);

    }
}

I use "var folder_win = sessionWinForm.FindElementByName("Browse For Folder");" error: OpenQA.Selenium.WebDriverException: An element could not be located on the page using the given search parameters.

anunay1 commented 2 months ago

You need to create a root session and then switch to the pop up window.

jainchengithub commented 2 months ago

How to create a root session? Do you have the code to do it?

Thanks!

anunay1 commented 2 months ago

https://github.com/microsoft/WinAppDriver/blob/master/Docs%2FFAQ.md

jainchengithub commented 2 months ago

Hi, if I want to open a excel file and save the test result (pass/fail) to related cell value, where can I find the sample code?

Shakevg commented 2 months ago

Hi, if I want to open a excel file and save the test result (pass/fail) to related cell value, where can I find the sample code?

Get test result value for mstest (something the same you can find for other runners): https://stackoverflow.com/questions/13201566/how-to-get-test-result-status-from-mstest Working with Excel https://www.mycplus.com/tutorials/csharp-programming-tutorials/read-write-excel-files-csharp/