-1

Issue: My selenium script is not recognizing and closing a dialog box that pops up when I redirect to a URl that contains file to download. The attached image shows the dialog I am referring to.

I know this has been asked a million times and I have spent at least 24 hours researching and trying other suggestions posted across the web but with no success. I am hoping the attached image will clarify which Firefox dialog box I am referring too.

I have tried the following solutions
1. Creating IAlerts (Alert element is not found)
2. Searching by trying to find the element by xpath (xpath to cancel was not found)
3. WindowsHandler Method (was not able to figure out the window name)

Any help on this would be greatly appreciated. Thank You in advance!

FireFox Dialog

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Jose Dias
  • 1
  • 1
  • you need to use `sendKeys` to work with that dialog. You may need to switch to it by window handle (you don't need name, just record existing handles before dialog appears, and see which new handle was added after it appeared). See bunch of options here: http://stackoverflow.com/questions/11256732/how-to-handle-windows-file-upload-using-selenium-webdriver – timbre timbre Jun 16 '16 at 20:30
  • Thank you for the comment. I have been through all of the examples in the link you shared and still not able to recognize that window. Looping through the handles is not recognizing the dialog box. The list of window handles only ever hold the initial window, so there is no way to assign it to a webelement to use the SendKeys method. Any other thoughts? – Jose Dias Jun 21 '16 at 15:05

2 Answers2

0

There are several types of "popups".

  1. Javascript dialogs - These are NOT HTML dialogs but are instead Javascript created dialogs. These consist of alert(), confirm(), and prompt() and can be handled with Alert.
  2. HTML dialogs - These take on various forms depending on how they are formatted. If you right-click on the dialog and see the typical context menu for your browser, then it's an HTML dialog. They are part of the DOM of the current page so you can use Selenium to access this just as you would any other page (e.g., no window handles needed).
  3. Browser window - These are actually another browser window that pops up and may look like a dialog, depending on how it's formatted. It's different than an HTML dialog because it can be moved outside of the current browser page frame. You will need to use window handles to access these windows as you would another tab in the browser. Once you get ahold of the window handle, you can access the HTML of the page like any other page.
  4. Browser dialog - these take on various forms but are akin to System dialogs. They are not made up of HTML so they cannot be accessed by Selenium. Other than using a library to access them, you can interact with them in a limited fashion by sending keys such as <SPACE>, <TAB>, <ENTER>, etc.

What you have pictured is a (4) browser dialog. They it takes on different forms depending on the browser you do the action on. Your best course of action is probably send keys. Sometimes, depending on the browser, you can specify settings to autodownload a file to a specific location so that the dialog doesn't come up. I've never used this so I can't direct you there.

JeffC
  • 22,180
  • 5
  • 32
  • 55
0

I was able to find and close a download dialog box by checking the amount of open windows after the dialog appears. This solution worked for me.

Find a link to open a dialog and click it:

    var link = MyBrowser.Driver.FindElement(OpenQA.Selenium.By.Id("Button"));

    IJavaScriptExecutor js = driver as IJavaScriptExecutor;
    js.ExecuteScript("arguments[0].click();", link);

Get the new window count after the dialog opens:

    var newWindowCount = MyBrowser.Driver.WindowHandles.Count;

Switch to the newly opened dialog and close it:

    MyBrowser.Driver.SwitchTo().Window(MyBrowser.Driver.WindowHandles[newWindowCount-1]);

    MyBrowser.Driver.Close();
JanneP
  • 577
  • 4
  • 12
  • Welcome to Stack Overflow! While this code may solve the asker's problem, it would be preferable to explain how it works - you can do so by [edit]ing your answer. – The SE I loved is dead Oct 20 '16 at 20:53