2013-03-08 48 views
0

我使用硒web驱动程序(不是硒RC)。我需要点击一个链接下载一个xml文件。我做了一些Google搜索,并且在某些答案中发现了使用AutoIT来处理操作系统相关的对话框。如何使用硒web驱动程序处理Windows下载对话框

但是,有没有其他的选择使用硒来处理这个,而不使用AutoIT工具。

请提出一些想法。

回答

0

你可以更具体一点你正在使用的浏览器。如果是Firefox,你可以对文件下载有更好的控制。包括Firefox在内的任何其他浏览器都可以使用机器人课程。这可以用来执行点击确定按钮进行下载。如果它的chorme然后文件下载自动发生没有任何干预。

+0

我使用的Firefox 11.0。当我使用Chrome时,当我点击下载链接时,它会要求保留或放弃选项。 – Naren 2013-03-11 04:16:27

0

对于最新版本的Firefox(截至撰写),这些是我需要避免下载框的参数。请注意,您需要指定,你可以写在第三条语句看到一个目录:

FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference("browser.download.folderList", 2); 
profile.setPreference("browser.download.dir", <YOUR DOWNLOAD PATH>); 
profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf"); 
profile.setPreference(
        "browser.helperApps.neverAsk.saveToDisk", 
    "application/csv,text/csv,application/pdfss, application/excel"); 
profile.setPreference("browser.download.manager.showWhenStarting", false); 
profile.setPreference("pdfjs.disabled", true); 

注意与pdfjs最后一行需要为Firefox,它以前是不可能的较新版本。更多信息Here

0

我在我的项目中遇到了Authentication Proxy弹出式问题。所以我尝试了下面的解决方案,它工作正常。 当我们在安全环境中运行Selenium Web驱动程序中的脚本时,需要完成安装以处理认证代理。

首先,你需要知道以下细节,

  • network.proxy.autoconfig_url(例: “http://example.com/abc.pac”)
  • network.proxy.http(例如:abc-proxy.com)
  • network.proxy.http_port(实施例:8080)

    private static WebDriver initFirefoxDriver(String appURL) 
    { 
    
        System.out.println("Launching Firefox browser.."); 
    
        FirefoxProfile firefoxProfile = new FirefoxProfile(); 
        firefoxProfile.setPreference("network.proxy.type", 1); 
        firefoxProfile.setPreference("network.proxy.autoconfig_url", "http://example.com/abc.pac"); 
        firefoxProfile.setPreference("network.proxy.http", " abc-proxy.com"); 
        firefoxProfile.setPreference("network.proxy.http_port", 8080); 
    
    
        WebDriver driver = new FirefoxDriver(firefoxProfile); 
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
        driver.manage().window().maximize(); 
        driver.navigate().to(appURL); 
        //driver.get(appURL); 
        return driver; 
    } 
    
相关问题