简体   繁体   English

Watir-加载Firefox默认配置文件-权限被拒绝

[英]Watir - Load Firefox default profile - Permission denied

I'm using Watir in a Ruby script to automatically download some files and I have a little problem : 我在Ruby脚本中使用Watir来自动下载一些文件,但是我有一个小问题:

If Firefox is already running, I get a "permission denied" error when I try to load firefox default profile. 如果Firefox已经在运行,则在尝试加载Firefox默认配置文件时出现“权限被拒绝”错误。 I know it's quite normal... But I really need my firefox default profile. 我知道这很正常……但是我确实需要我的firefox默认配置文件。

So my question is : 所以我的问题是:

  • Is there any solution to access the default profile even if firefox is already running ? 即使firefox已经在运行,是否有解决方案可以访问默认配置文件?
  • If not, when firefox isn't running and so when I have no error, how can I export the profile I load in my Watir browser (in a text file) ? 如果没有,当firefox未运行且没有错误时,如何导出在Watir浏览器中加载的配置文件(在文本文件中)? (for using it later if firefox is already running) (以供以后在已运行firefox的情况下使用)

Something like above : 像上面的东西:

Mozilla = Watir::Browser.new(:firefox, :profile => "default")
file = File.open("path", 'w')
file.write(Mozilla.export_profile())

and then in another script : 然后在另一个脚本中:

profile = Selenium::WebDriver::Firefox::Profile.new(File.read("path"))
Mozilla = Watir::Browser.new(:firefox, :profile => profile)

Or I have to export (and then load) each property one by one ? 还是我必须逐一导出(然后加载)每个属性?

the behaviour you are seeing is normal and correct. 您看到的行为是正常且正确的。
The are two way to work around his: 解决他的两种方法:

  1. create a new profile dedicated to Webdriver scripts (using Firefox), and use it. 创建一个专用于Webdriver脚本的新配置文件(使用Firefox),然后使用它。 This will keep cache and cookies from one test to another. 这样可以将缓存和cookie从一项测试保留到另一项测试。
  2. if you do not choose any profile, a new, clean profile is created each time you start Webdriver, and it is deleted at the end. 如果您不选择任何配置文件,则每次启动Webdriver时都会创建一个干净的新配置文件,并在最后将其删除。 This is slower and do not keep any memory from previous runs. 这样比较慢,并且不会保留以前运行的任何内存。

The choice depends on what you need. 选择取决于您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM