microsoft / WinAppDriver

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

I have a problem with pop up window and after Upgrade sellenium to 4.0 is not working #1977

Open MaxMaxMaks opened 3 months ago

MaxMaxMaks commented 3 months ago

I launched the program, and after clicking a button, a new window popped up where I must enter the password and press Enter. I've been working on this for two weeks and don't know how to handle it. Also, after upgrading Selenium to version 4.0, I cannot launch this. Can somebody please help me with this? Make corrections if necessary.

using OpenQA.Selenium.Appium; using OpenQA.Selenium.Appium.Enums; using OpenQA.Selenium.Appium.Windows; using OpenQA.Selenium.Remote; using System; using System.Diagnostics; using System.Threading; using System.Collections.ObjectModel; using Microsoft.VisualBasic; using OpenQA.Selenium; using System.Runtime.CompilerServices; using OpenQA.Selenium.Support.UI; using System.Text.RegularExpressions;

class Program { public static void Main(string[] args) { // Start WinAppDriver process //Process.Start(@"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe"); AppiumOptions options = new AppiumOptions(); options.AddAdditionalCapability("app","Root"); options.AddAdditionalCapability("app", @"C:\Program Files (x86)\InsLauncher.exe"); options.AddAdditionalCapability("deviceName", "SERWER"); options.AddAdditionalCapability("appArguments", "N/R");

    WindowsDriver<WindowsElement> driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), options);
        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(7);

    var podmiot = driver.FindElementByXPath("//Window[@ClassName=\'Window\'][@Name=\'R\']/Custom[@ClassName=\'SelectDatabasesControl\']/Custom[@AutomationId=\'BazaPodmiotu\']/ComboBox[@AutomationId=\'cbxBaza\']");
    podmiot.SendKeys(" B");
    podmiot.SendKeys(Keys.Enter);

     var aktualizujAndRun = driver.FindElementByXPath("//Button[@Name=\'Aktualizuj i uruchom\'][@AutomationId='btnAktualizujIUruchom']");
     aktualizujAndRun.Click();

    Thread.Sleep(5000);

    AppiumOptions upp = null;
    WindowsDriver<WindowsElement> secondDriver = null;
    Console.WriteLine("TUTAJ");
    var listofAllWindow = driver.FindElementsByXPath("//Window");   
    string s="Aktualizacja podmiotu";

    foreach(var w in listofAllWindow)
    {
        Console.WriteLine($"{w.Text}");
         if( w.Displayed && w.Text.Contains("Aktualizuj"))
             {
                var windowHandle = w.GetAttribute("NativeWindowHandle");
                Console.WriteLine($"Window Handle: {windowHandle}");

                var handleInt = (int.Parse(windowHandle)).ToString("x");
                upp = new AppiumOptions();
                upp.AddAdditionalCapability("appTopLevelWindow", handleInt);
                break;                
            }
    }
        if (upp != null){
        secondDriver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), upp);
        secondDriver.Keyboard.SendKeys(Keys.Escape);
        secondDriver.Keyboard.SendKeys("2*2"+ Keys.Enter);
            }

    Thread.Sleep(10000);

    //driver.CloseApp();
   driver.Quit();
}
anunay1 commented 3 months ago

Winappdriver does not support selenium 4, it will not work.

MaxMaxMaks commented 3 months ago

What should I do ?

anunay1 commented 3 months ago

Downgrade to 3.141.1.

MaxMaxMaks commented 3 months ago

In the End this resolve my problem with pop up window ?

anunay1 commented 3 months ago

Is that a question?