0

我正在使用 selenium web 驱动程序(不是 selenium RC)。我需要通过单击链接下载 xml 文件。我做了一些谷歌搜索,并在一些答案中找到了使用 AutoIT 来处理与操作系统相关的对话框。

但是在不使用 AutoIT 工具的情况下,是否有任何其他选项使用 selenium 来处理这个问题。

请提出一些想法。

4

3 回答 3

0

您能否更具体地说明您使用的是哪个浏览器。如果是 Firefox,您可以更好地控制文件下载。包括 Firefox 在内的任何其他浏览器都可以使用机器人类。这可用于执行单击确定按钮以进行下载。如果它的 chorme 则文件下载会自动发生,无需任何干预。

于 2013-03-08T09:39:54.417 回答
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 );

请注意,新版本的 Firefox 需要最后一行 pdfjs,而以前不需要。更多信息在这里

于 2014-04-03T14:11:27.147 回答
0

我在我的项目中遇到身份验证代理弹出问题。所以我尝试了下面的解决方案,它工作正常。当我们在安全环境中从 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;
    }
    
于 2016-11-25T07:08:45.593 回答