python-3.x - webdriver.FirefoxProfile() : Is it possible to use a profile without making a copy of it?

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

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

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

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

最佳答案

根据当前使用 FirefoxProfile() 在 Firefox 中实现的 GeckoDriver工作原理如下:

  • 如果通过新的 启动浏览 session 火狐个人资料 如下 :
    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 被完全删除/销毁。
  • 再次在通过现有 启动浏览 session 的情况下Firefox 配置文件() 如下 :
    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.2oSwrQwQby9 被完全删除/销毁。
  • 所以你观察的时间跨度是 所需的时间FirefoxProfile() 挖出一个新的 rust_mozprofile .

  • 也许根据您的问题,复制配置文件的时间跨度(例如> 30 分钟)是纯粹的开销。因此,如果不复制 rust_mozprofile,就无法使用 Firefox 配置文件。 .

    解决方案
  • 将 Selenium 客户端升级到当前级别 Version 3.11.0 .
  • 将 GeckoDriver 升级到当前版本 GeckoDriver v0.20.0等级。
  • 将 Firefox 版本升级到 火狐量子 v59.0.1 水平。
  • 通过 IDE 清理项目工作区并仅使用所需的依赖项重建项目。
  • 使用 CCleaner在执行测试套件之前和之后清除所有操作系统杂务的工具。
  • 如果您的基础 Firefox 基础版本太旧,请通过 Revo Uninstaller 卸载它并安装最新的 GA 和发布版本的 Firefox Quantum。
  • 执行您的 @Test .
  • 关于python-3.x - webdriver.FirefoxProfile() : Is it possible to use a profile without making a copy of it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49356081/

    相关文章:

    java - 如何等待然后点击html表格中的第一个链接

    Angular2 @angular/cli e2e 错误 : tunneling socket could not be established, statusCode=400

    java - 无法从 Selenium Java 的 html 元素获取文本

    python - python错误,尝试创建结构列表时语法无效

    Python 脚本不起作用,但也不给出错误

    python - 在 Python 中使用 Selenium 按类名查找元素

    java - firefox selenium webdriver 错误

    python - 区分大小写的列表排序,但只是重复的值?

    python - 按值迭代多个列表

    javascript - 如何将属性设置为使用 selenium javascript?