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

1 Answer 1

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();
        }
9
  • I already checked it but not sure how to use thes capabilities as I am new to Safari.
    – Himanshu
    Jan 9, 2014 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, 2014 at 7:14
  • Sorry did not understood. Why you want to disable the dialog.
    – A Paul
    Jan 10, 2014 at 8:06
  • Not disable actually, I want file to get downloaded wihtout any popup coming in between to click 'save' or 'Open'.
    – Himanshu
    Jan 10, 2014 at 8:10
  • Do you mean once you download safari is asking you to choose a location for the file to save ?
    – A Paul
    Jan 10, 2014 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.