1

I would like to know it there is any desired capability or options setting for Safari selenium webdriver to save file to specific location Similar as we do it for firefox driver.

Also want to disable the popup for file save dialog.

Regards, Himanshu

Himanshu
  • 648
  • 4
  • 11

1 Answers1

0

You can check the below link. dataDir mar do you work but not sure

http://code.google.com/p/selenium/wiki/DesiredCapabilities#Safari_specific

Try this

Selenium sel = new DefaultSelenium("localhost", 4444, "*safari", baseURL);
CommandExecutor executor = new SeleneseCommandExecutor(sel);
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("safari.options.dataDir", "your folder path");
WebDriver browser = new RemoteWebDriver(executor, dc);

NEW UPDATE : TO CLOSE THE SAVE DOWNLOAD WARNING

WebElement link = driver.findElement(By.xpath("myxpath"));
clickAndSaveFileIE(link);


public static void clickAndSaveFileIE(WebElement element) throws InterruptedException{
    try {
            Robot robot = new Robot();
             //get the focus on the element..don't use click since it stalls the driver          
            element.sendKeys("");
            //simulate pressing enter            
            robot.keyPress(KeyEvent.VK_ENTER);
            robot.keyRelease(KeyEvent.VK_ENTER);
            //wait for the modal dialog to open            
            Thread.sleep(2000);
            //press s key to save            
            robot.keyPress(KeyEvent.VK_S);
            robot.keyRelease(KeyEvent.VK_S);
            Thread.sleep(2000);
            //press enter to save the file with default name and in default location
            robot.keyPress(KeyEvent.VK_ENTER);
            robot.keyRelease(KeyEvent.VK_ENTER);
        } catch (AWTException e) {

            e.printStackTrace();
        }
A Paul
  • 8,113
  • 3
  • 31
  • 61
  • I already checked it but not sure how to use thes capabilities as I am new to Safari. – Himanshu Jan 09 '14 at 12:22
  • It worked for adding data directory path. also please suggest how to disable the download popup (file save dialogue) for safari. – Himanshu Jan 10 '14 at 07:14
  • Sorry did not understood. Why you want to disable the dialog. – A Paul Jan 10 '14 at 08:06
  • Not disable actually, I want file to get downloaded wihtout any popup coming in between to click 'save' or 'Open'. – Himanshu Jan 10 '14 at 08:10
  • Do you mean once you download safari is asking you to choose a location for the file to save ? – A Paul Jan 10 '14 at 08:20
  • Yes, once webdriver click on file download button, a file save dialog pops up(Do you want to save this file?) and my test execution freezes.The file is archive(.zip) file.I don't want this dialog same as we do in firefox. – Himanshu Jan 10 '14 at 08:30
  • Check my edit. Probably will work for you but not sure. Give it a try. – A Paul Jan 10 '14 at 08:34
  • You can also check this link http://sqa.stackexchange.com/questions/3169/downloading-a-file-in-internet-explorer-through-selenium – A Paul Jan 10 '14 at 08:49
  • If the answer helped you solve your problem please dont forget to mark the answer as correct :) – A Paul Jan 10 '14 at 09:24