Keliimek
Keliimek

Reputation: 161

close download popup window java

I'm using Selenium Webdriver in Java and I want to verify if is possible to download one document. When I click a link, its shown pup up download window and I need verify text from the title and close it. But I cannot click at the popup window and I don't know XPath etc. http://postimg.org/image/si2eagaqr/

driver.close(); this statement is useless for me

Can anyone advise me? I will be very grateful.

Upvotes: 4

Views: 1037

Answers (2)

fahad
fahad

Reputation: 389

Hello you can use robot for this purpose by pressing Enter please call the function below to press enter and it will press download button on UI . If this not works please let me know key sequence to perform this action .

public void pressEnter() throws AWTException, InterruptedException { 
Thread.sleep(5000);
 Robot rb=new Robot();
 rb.keyPress(KeyEvent.VK_ENTER);
      rb.keyRelease(KeyEvent.VK_ENTER); }

Upvotes: 0

Anton Angelov
Anton Angelov

Reputation: 1713

You can configure Firefox the directly download the files - File types and download actions

If you don't want to hardcode the setting for your browser, you can setup a specific FF profile only for your tests, where you can configure where you want the files to be downloaded.

FirefoxProfile firefoxProfile = new FirefoxProfile();

firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.download.dir","c:\\downloads");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");
WebDriver driver = new FirefoxDriver(firefoxProfile);

I suggest you to use the first approach is much simpler.

Upvotes: 2

Related Questions