Skip to content

[πŸ› Bug]: Notification popup is treated as window/tab in Edge - headlessΒ #14866

@saiparth

Description

@saiparth

What happened?

When we download a file in edge headless, a notification is displayed that file is downloaded. selenium thinks that its a tab. If I check driver.WindowHandles, its considering notification as one more tab, If I try to close the notification using driver.close since I was able to switch to it, its giving some error. Same code works fine in chrome.

If I run test by disabling headless, issue doesn't occur.

Expectation is that download popup should not be considered as a tab/window.

How can we reproduce the issue?

Download latest selenium and install nunit

 [TestClass]
 public class JsonUtility
 {
     private EdgeDriver? driver;
     const string fileName = "Downloads//Financial Sample.xlsx";

     [TestMethod]
     public void EdgeDownloadBug()
     {
         try
         {
             var downloadDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Downloads");
             Directory.CreateDirectory(downloadDirectory);
             if (File.Exists(fileName))
             {
                 File.Delete(fileName);
             }
             var options = new EdgeOptions();
             options.AddArgument("headless=new");//comment this line to reproduce the bug
             options.AddArgument("--no-sandbox");
             options.AddArgument("--disable-dev-shm-usage");
             options.AddUserProfilePreference("download.default_directory", downloadDirectory);
             options.AddUserProfilePreference("download.prompt_for_download", false);
             options.AddUserProfilePreference("directory_upgrade", true);
             options.AddUserProfilePreference("safebrowsing.enabled", true);

             driver = new (options);
             driver.Manage().Timeouts().ImplicitWait=TimeSpan.FromSeconds(5);
             driver.Url = "https://learn.microsoft.com/en-us/power-bi/create-reports/sample-financial-download";
             driver.FindElement(By.LinkText("Financial Sample Excel workbook")).Click();

             Thread.Sleep(5000);
             Assert.IsTrue(File.Exists(fileName));
             foreach (var item in driver.WindowHandles)
             {
                 driver.SwitchTo().Window(item);
                 Console.WriteLine($"Page Title: {driver.Title}");
                 Console.WriteLine($"Current URL: {driver.Url}");
             }
             try
             {
                 driver.Close();
             }
             catch (Exception e)
             {
                 Console.WriteLine(e.ToString());
             }
             Assert.AreEqual(1, driver.WindowHandles.Count,"There should be only one window/tab");
         }
         finally
         {
             driver?.Quit();
         }

     }
     [TestMethod]
     public void ChromeDownloadBug()
     {
         try
         {
             var downloadDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Downloads");
             Directory.CreateDirectory(downloadDirectory);
             if (File.Exists(fileName))
             {
                 File.Delete(fileName);
             }
             var options = new ChromeOptions();
             options.AddArgument("headless=new");//comment this line to reproduce the bug
             options.AddArgument("--no-sandbox");
             options.AddArgument("--disable-dev-shm-usage");
             options.AddUserProfilePreference("download.default_directory", downloadDirectory);
             options.AddUserProfilePreference("download.prompt_for_download", false);
             options.AddUserProfilePreference("directory_upgrade", true);
             options.AddUserProfilePreference("safebrowsing.enabled", true);

             var driver = new ChromeDriver(options);
             driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
             driver.Url = "https://learn.microsoft.com/en-us/power-bi/create-reports/sample-financial-download";
             driver.FindElement(By.LinkText("Financial Sample Excel workbook")).Click();

             Thread.Sleep(5000);
             Assert.IsTrue(File.Exists(fileName));
             foreach (var item in driver.WindowHandles)
             {
                 driver.SwitchTo().Window(item);
                 Console.WriteLine($"Page Title: {driver.Title}");
                 Console.WriteLine($"Current URL: {driver.Url}");
             }
             Assert.AreEqual(1, driver.WindowHandles.Count, "There should be only one window/tab");
         }
         finally
         {
             driver?.Quit();
         }

     }
 }


### Relevant log output

```shell
OpenQA.Selenium.WebDriverException: unknown error: failed to close window in 20 seconds
  (Session info: MicrosoftEdge=131.0.2903.70)
   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
   at OpenQA.Selenium.WebDriver.ExecuteAsync(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.Close()

Operating System

Win 11

Selenium version

C# 4.27.0

What are the browser(s) and version(s) where you see this issue?

Edge Version 131.0.2903.86 (Official build) (64-bit)

What are the browser driver(s) and version(s) where you see this issue?

Using selenium to download driver

Are you using Selenium Grid?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!G-msedgedriverRequires fixes in MSEdgeDriverI-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions