【问题标题】:Ruby interacting with Selenium to control Firefox open/save dialogRuby 与 Selenium 交互以控制 Firefox 打开/保存对话框
【发布时间】:2017-08-14 23:28:44
【问题描述】:

Capybara.register_driver :session do |app| profile = Selenium::WebDriver::Firefox::Profile.new Capybara::Selenium::Driver.new app, :profile => profile end

我在这里添加什么来让我的 ruby​​ 脚本告诉 Selenium(我在 MAC OS El Capitan 上运行)与 Firefox 打开/保存对话框交互,以便它自动打开 PDF 或 DOC 文件而不是提示需要人工干预的对话框?

【问题讨论】:

  • 不知道你想要什么,有详细点吗?
  • 我查看了上面的一个链接,但我很难解析很多答案(其中一些不相关)。我想知道我需要在上面的语句中添加什么 ruby​​ 代码,这样当对话框出现时,我可以选择是在浏览器中使用插件打开 pdf 还是将文件保存起来。

标签: ruby selenium firefox dialog


【解决方案1】:

您无法使用 selenium-webdriver 和 firefox 与“打开/保存”对话框进行交互。但是,您可以在驱动程序中设置首选项,以使对话框永远不会出现,而默认行为只会发生。类似的东西

Capybara.register_driver :session do |app|
  profile = Selenium::WebDriver::Firefox::Profile.new
  profile['browser.download.dir'] = "~/Downloads"
  # Adjust below to match the type of file reported
  profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf, application/octet-stream" 
  Capybara::Selenium::Driver.new app, :profile => profile
end

应该让它总是在没有提示的情况下下载文件。您可以类似地设置“browser.helperApps.neverAsk.openFile”配置文件设置以始终打开特定类型的文件。

【讨论】:

  • 尝试打开 PDF 文件时,它仍然给我一个对话框。 Capybara.default_driver = :selenium Capybara.register_driver :selenium do |app| profile = Selenium::WebDriver::Firefox::Profile.new profile['browser.download.dir'] = "~/Downloads" profile['browser.helperApps.neverAsk.saveToDisk'] = "application/doc, application/ pdf, application/octet-stream" Capybara::Selenium::Driver.new app, :profile => profile end
  • 在您的回答中对上述命令的手册页有任何很好的参考,也将不胜感激,并且对浏览器配置文件的描述也将不胜感激。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-02
  • 2011-07-06
  • 1970-01-01
  • 1970-01-01
  • 2012-06-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多