0

I'm trying to debug why when running remote webdriver tests on a headless linux host download dialogs are presented in chrome. I believe the chrome version is 45.

Couple of Env Details

  1. Selenium 2.53 (gem)
  2. Selenium 2.53 Server Jar
  3. Chrome Driver 2.21

The framework/Tests are written in Ruby utilizing Capybara for driving web tests. Here is a brief snippet of how the remote driver is initialized.

            prefernces = {
          :download => {
            :prompt_for_download => false, 
            :default_directory => '/home/john.doe/Downloads/'
          }
        }
        caps = Selenium::WebDriver::Remote::Capabilities.chrome()
        caps['chromeOptions'] = {'prefs' => prefernces}

      http_client = Selenium::WebDriver::Remote::Http::Default.new
      http_client.timeout = 240
      options = {
        browser: :remote,
        url: "http://<server_url>:4444/wd/hub",
        desired_capabilities: caps,
        http_client: http_client
      }
      # Returns Remote Driver
      Capybara::Selenium::Driver.new(app, options)

I have verified via the hub that the chromeOptions are set, but when a file is downloaded, we're presented with a file dialog prompt.

I've burned the candle looking for a solution to this problem. Thanks for the help and consideration!

4

2 回答 2

3

尝试从 default_directory 的末尾删除 / 并设置 directory_upgrade: true。除此之外,请确保浏览器有权写入所选目录(还要注意首选项的正确拼写)

 preferences = {
      :download => {
        :default_directory => '/home/john.doe/Downloads',
        :directory_upgrade => true,
        :prompt_for_download => false, 

      }
    }
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
  'chromeOptions' => {'prefs' => preferences}
)
于 2016-04-27T23:44:43.060 回答
1

这是使用 Capybara / Selenium / Chrome 下载文件的示例:

require 'capybara'
require 'selenium-webdriver'

Capybara.register_driver :chrome do |app|
  Capybara::Selenium::Driver.new(app,
    :url => "http://localhost:4444/wd/hub",
    :browser => :chrome,
    :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.chrome(
      'chromeOptions' => {
        'prefs' => {
          'download.default_directory' => File.expand_path("C:\\Download"),
          'download.directory_upgrade' => true,
          'download.prompt_for_download' => false,
          'plugins.plugins_disabled' => ["Chrome PDF Viewer"]
        }
      }
    )
  )
end

session = Capybara::Session.new(:chrome)
session.visit "https://www.mozilla.org/en-US/foundation/documents"
session.click_link "IRS Form 872-C"

sleep 20
于 2016-04-28T00:15:53.417 回答