microsoft / WinAppDriver

Windows Application Driver
MIT License
3.69k stars 1.4k forks source link

Argument 1: Unable to convert from "System.Uri в OpenQA.Selenium.AppiumOptions;" & Argument 2: Unable to convert from "OpenQA.Selenium.Remote.DesiredCapabilities" в "System.TimeSpan"; #1654

Open MrMikheev opened 2 years ago

MrMikheev commented 2 years ago

My application starts, but it has a splash screen. wiki doesn’t help me because swears at (new Uri("http://127.0.0.1:4723"), appCapabilities);

image

the application has a splash screen, it is impossible to create a root session, as it is written in the wiki

anunay1 commented 2 years ago

Try this:

Get the application name first if the application is already opened:

 string mainWindowTitle = "";
                var allProcesses1 = Process.GetProcesses();
                foreach (Process process in allProcesses1)
                {
                    if (process.ProcessName.Contains("Your Application"))
                    {
                        mainWindowTitle = process.MainWindowTitle; 
                    }
                }

use the below code to create a driver session with opened application:

                desktopCapabilities.AddAdditionalCapability("app", "Root");
                desktopSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), desktopCapabilities);
                Assert.IsNotNull(desktopSession);

                var RSWindow = desktopSession.FindElementByName(mainWindowTitle);
                var RSTopLevelWindowHandle = RSWindow.GetAttribute("NativeWindowHandle");
                RSTopLevelWindowHandle = (int.Parse(RSTopLevelWindowHandle)).ToString("x");

                var appcapabilities = new AppiumOptions();
                appcapabilities.AddAdditionalCapability("appTopLevelWindow", RSTopLevelWindowHandle);
                appcapabilities.AddAdditionalCapability("newCommandTimeout", 300);
                driver = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appcapabilities,TimeSpan.FromSeconds(50));
anunay1 commented 2 years ago

@MrMikheev Did it work?

rogerms commented 1 year ago

I solved the "Unable to convert from "System.Uri to OpenQA.Selenium.AppiumOptions" error by modifying the code: FROM:

DesiredCapabilities appCapabilities1 = new DesiredCapabilities();
appCapabilities1.SetCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
var calculatorSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl);, appCapabilities);

TO:

var appCapabilities = new AppiumOptions();
appCapabilities.AddAdditionalCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
appCapabilities.AddAdditionalCapability("deviceName", "WindowsPC");
appCapabilities.AddAdditionalCapability("platformName", "Windows");
var calculatorSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities, TimeSpan.FromSeconds(180));
byronv5 commented 1 year ago

https://github.com/microsoft/WinAppDriver/issues/1590#issuecomment-1404661544