Winappdriver: Allow to attach the process based on Process ID

Created on 5 Mar 2020  路  7Comments  路  Source: microsoft/WinAppDriver

Appium option should allow to attach the currently running process based on the Process ID

Most helpful comment

This will attach the currently running process to session without using Root session

var processes = Process.GetProcesses();
bool exi = false;
foreach (var process in processes)
{

            string v = "";
            try
            {
                v = process.MainModule.FileName;
            }
            catch { }
            if (v.ToUpper() == ApplicationPath.ToUpper())
            {
                WindowHandle = process.MainWindowHandle.ToString("x");
                exi = true;
                break;
            }
        }

        //////////
        AppiumOptions Prop = new AppiumOptions();
        Prop.AddAdditionalCapability("appTopLevelWindow", WindowHandle);
        Prop.AddAdditionalCapability("deviceName", "WindowsPC");
        Prop.AddAdditionalCapability("platformName", "Windows");

        Session = new WindowsDriver<WindowsElement>(new Uri(@"http://localhost:4723/"), Prop);

All 7 comments

This is a feature request.

This will attach the currently running process to session without using Root session

var processes = Process.GetProcesses();
bool exi = false;
foreach (var process in processes)
{

            string v = "";
            try
            {
                v = process.MainModule.FileName;
            }
            catch { }
            if (v.ToUpper() == ApplicationPath.ToUpper())
            {
                WindowHandle = process.MainWindowHandle.ToString("x");
                exi = true;
                break;
            }
        }

        //////////
        AppiumOptions Prop = new AppiumOptions();
        Prop.AddAdditionalCapability("appTopLevelWindow", WindowHandle);
        Prop.AddAdditionalCapability("deviceName", "WindowsPC");
        Prop.AddAdditionalCapability("platformName", "Windows");

        Session = new WindowsDriver<WindowsElement>(new Uri(@"http://localhost:4723/"), Prop);

Thanks very much for the answer, I didn't know it was a possibility.

@naeemakram you can use next method https://github.com/microsoft/WinAppDriver/issues/534#issuecomment-562030077

@naeemakram you can use next method #534 (comment)

Thanks for the tip

Process.GetProcesses() is working on local machine. how can we get processes in remote machine ? via remote WinAppDriver, I start an application, the application has a separate dialog. from Inspect, it is independent from the main session but has the same pid. my problem is how to get a windows handle for that dialog. windAppDriver.WindowHandles only give me the main windows.
thanks and regards

Yes it is not possible to get Window handle from a remote machine. If any one can give suggestion to get WindowsHandle from a remote machine will be very helpful.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mdesousa picture mdesousa  路  4Comments

ant-skelia picture ant-skelia  路  4Comments

SimonKirkhamCL4U picture SimonKirkhamCL4U  路  3Comments

RajneeshK2018 picture RajneeshK2018  路  4Comments

AmitVerma4HP picture AmitVerma4HP  路  4Comments