小编典典

webdriver.FirefoxProfile():是否可以不复制配置文件就使用配置文件?

selenium

如文档所述,您可以使用可选参数调用webdriver.FirefoxProfile()profile_directory来指向浏览器要使用的特定配置文件的目录。我注意到运行此命令花了很长时间,因此当我查看代码时,似乎正在复制指定的配置文件问题是,复制配置文件需要很长时间(大约>
30分钟,没有耐心等待它完成。)

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

是更改此行为以编辑firefox_profile.py自身的唯一方法(如果是,执行此操作的最佳方法是什么?)?


阅读 836

收藏
2020-06-26

共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分钟以上) 纯属开销。因此,如果不复制,就无法使用
Firefox配置文件rust_mozprofile


  • Selenium Client 升级到当前 版本3.11.0
  • 升级 GeckoDriver 当前 GeckoDriver v0.20.0 水平。
  • Firefox 版本升级到 Firefox Quantum v59.0.1 级别。
  • 清理 你的 项目工作 ,通过你的 IDE重建 仅需要依赖你的项目。
  • 在执行 测试套件 之前和之后,使用 CCleaner 工具清除所有操作系统琐事。 __
  • 如果您的基本 Firefox 基本版本太旧,请通过 Revo Uninstaller 卸载它,并安装最新的GA和 Firefox Quantum的 发行版本。
  • 执行您的@Test
2020-06-26