how to handle file downlaod for selenium webdriver for safari

前端 未结 1 696
挽巷
挽巷 2021-01-07 13:47

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 dr

相关标签:
1条回答
  • 2021-01-07 13:58

    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();
            }
    
    0 讨论(0)
提交回复
热议问题