'How to Handle Browser Popup (During the Download) using Java

currently we scrap the data from Websites using Web driver (Selenium)with Java, during that Scrapping we need to do some download process (i.e XML file Download), let me know how will handle the Browser Popup (save As Dialog) using Java

<a href="javascript:downloadXML()">
    <img width="40" height="20" border="0" name="imag34" alt="Download" src="/pair/img/tabs/downloadxml.gif">
</a>

We are using the following code to click the above image

driver.findElement(By.xpath("(//img[@alt='Download'])[3]")).click();

After clicking that image, it will open a "Save as.." popup. How do we go to that popup and do testing on that?

enter image description here



Solution 1:[1]

This download popup is basically a window.open Javascript call with the URL of the XML file. So this seems to be the relevant link :

How to switch to the new browser window, which opens after click on the button?

Solution 2:[2]

I've just solved this problem using the Robot class from Java. The Robot class allow you to simulate keybord press, in so doing you can work with TABs and Enters in order to execute the download.

Solution 3:[3]

This is actually a windows pop up and firebug will not able to detect this.If you are using windows OS then you can use AutoIT tool this will solve your problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 user3328505
Solution 3 srinivas