0

I am doing automation using selenium with testng. I have ubuntu OS. I need to download a pdf file and verify its content. I click on a button, a new window opens whose content's view is like pdf. (What that kind of page is called ? I mean when I save it, its saved as pdf but its url is that of a web page). Then I click on download on the newly opened window and a pop-up comes. I want to know how to handle this ?

I searched about this and here is my code now:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.helperapps.neverAsk.saveToDisk" , "application/octet-stream;application/pdf"); 
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.showWhenStarting",false);
        profile.setPreference("browser.download.folderList", 2); 
        profile.setPreference("browser.download.dir",System.getProperty("user.dir"));

driver =new FirefoxDriver(profile);

Thanks :)

user3433848
  • 117
  • 1
  • 2
  • 10

2 Answers2

0

I suppose when you click on a button you see the pdf preview. In Chrome you have the plugin for this purposes. In order to handle the popup please see the following code snippets. When you create the driver please save the appropriated handler

driver = new FirefoxDriver(profile);
driver.get(uri);
MainWinHandler = driver.getWindowHandle();

Then in order to switch:

for(String winHandle : driver.getWindowHandles()){
    if(!winHandle.equals(MainWinHandler))
        driver.switchTo().window(winHandle);
}

After the switching you have to be able to manage it with the WebDriver.

Eugene
  • 1,865
  • 3
  • 21
  • 24
  • Hi Eugene, I know how to switch to new window and successfully done so. What I want to know is how to handle that pop-up. I have firefox in my system. and I have set its profile as mentioned in the code above. But no luck.. :( – user3433848 Mar 02 '15 at 02:46
  • Could you please see if that similar to this [link](http://the-internet.herokuapp.com/download)? – Eugene Mar 02 '15 at 16:07
  • Also please see if that [link](http://stackoverflow.com/questions/1176348/access-to-file-download-dialog-in-firefox) will help. – Eugene Mar 02 '15 at 16:55
  • hey Eugene.. I forgot to update here... Actually I have solved it... needed to set one more preference there. updated in ques.. :) Still Thanks a ton for your time – user3433848 Mar 04 '15 at 07:21
0

I just needed to add this dependency also.

profile.setPreference("pref.downloads.disable_button.edit_actions", true); 
user3433848
  • 117
  • 1
  • 2
  • 10