【问题标题】:webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?webdriver.FirefoxProfile():是否可以使用配置文件而不复制它?
【发布时间】:2018-08-27 14:33:41
【问题描述】:

如文档所述,you can call webdriver.FirefoxProfile() 和可选参数 profile_directory 指向您希望浏览器使用的特定配置文件的目录。我注意到运行这个命令需要很长时间,所以当我查看代码时,它看起来像是在复制指定的配置文件问题是,配置文件的复制需要很长时间(大约 30 分钟,没有耐心等待它完成。)

我正在使用用户脚本和 selenium 的混合体来为我做一些自动化,所以每次我想测试我的代码时都设置一个新的配置文件会很麻烦。

改变这种行为的唯一方法是编辑firefox_profile.py 本身(如果是,最好的方法是什么?)?

【问题讨论】:

    标签: python-3.x selenium selenium-webdriver automation webdriver


    【解决方案1】:

    根据 GeckoDriverFirefox 的当前实现,使用 FirefoxProfile() 的工作方式如下:

    • 如果通过新的 Firefox 配置文件 启动 浏览会话 的情况如下:

      from selenium import webdriver
      
      myprofile = webdriver.FirefoxProfile()
      driver = webdriver.Firefox(firefox_profile=myprofile, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
      driver.get('https://www.google.co.in')
      print("Page Title is : %s" %driver.title)
      driver.quit()
      
    • 一个新的 rust_mozprofile 在运行时被创建如下:

      1521446301607   mozrunner::runner   INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\ATECHM~1\\AppData\\Local\\Temp\\rust_mozprofile.xFayqKkZrOB8"
      
    • 如果成功关闭(即成功调用 driver.quit()),临时 rust_mozprofile.xFayqKkZrOB8 会被完全删除/销毁。

    • 如果通过现有 Firefox Profile() 启动浏览会话,如下所示:

      from selenium import webdriver
      
      myprofile = webdriver.FirefoxProfile(r'C:\Users\AtechM_03\AppData\Roaming\Mozilla\Firefox\Profiles\moskcpdq.SeleniumTest')
      driver = webdriver.Firefox(firefox_profile=myprofile, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
      driver.get('https://www.google.co.in')
      print("Page Title is : %s" %driver.title)
      driver.quit()
      
    • 类似地,一个新的 rust_mozprofile 在运行时被创建如下:

      1521447102321   mozrunner::runner   INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "-marionette" "-profile" "C:\\Users\\ATECHM~1\\AppData\\Local\\Temp\\rust_mozprofile.2oSwrQwQoby9"
      
    • 同样地,在这种情况下以及在成功关闭(即成功调用 driver.quit())时,临时 rust_mozprofile.2oSwrQwQoby9 将被完全删除/销毁。

    • 所以您观察的 时间跨度FirefoxProfile() 挖出新的 rust_mozprofile 所需的时间。

    也许根据您的问题时间跨度,要复制的个人资料(大约 30 分钟) 纯粹是开销。因此,如果不复制 rust_mozprofile,就无法使用 Firefox 配置文件


    解决方案

    • Selenium 客户端升级到当前级别Version 3.11.0
    • GeckoDriver 升级到当前的GeckoDriver v0.20.0 级别。
    • Firefox 版本升级到 Firefox Quantum v59.0.1 级别。
    • 清理你的项目工作区通过你的IDE重建你的项目只需要依赖。
    • 使用CCleaner 工具在执行测试套件之前和之后清除所有操作系统杂务。
    • 如果您的基础 Firefox 基础版本太旧,请通过Revo Uninstaller 将其卸载并安装最新的 GA 和发布版本的 Firefox Quantum
    • 执行您的@Test

    【讨论】:

    • “解决方案”都没有解决用户的问题:如何让 firefox 在每次启动时不复制使用指定的配置文件。
    猜你喜欢
    • 1970-01-01
    • 2015-11-07
    • 2017-11-30
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多