webdriver.FirefoxProfile():是否可以在不复制的情况下使用配置文件? [英] webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?

查看:26
本文介绍了webdriver.FirefoxProfile():是否可以在不复制的情况下使用配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

As the documentation states, you can call webdriver.FirefoxProfile() with the optional argument of profile_directory to point to the directory of a specific profile you want the browser to use. I noticed it was taking a long time to run this command, so when I looked into the code, it looked like it was copying the specified profile Problem is, it takes an extremely long time for the profile to copy (something like >30 minutes, didn't have the patience to wait for it to finish.)

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

I'm using a hybrid of userscripts and selenium to do some automation for me, so to setup a new profile every single time I want to test out my code would be burdensome.

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

Is the only way to change this behaviour to edit the firefox_profile.py itself (if so, what would be the best way to go about it?)?

推荐答案

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

As per the current implementation of GeckoDriver with Firefox using the FirefoxProfile() works as follows :

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

from selenium import webdriver

myprofile = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_profile=myprofile, executable_path=r'C:UtilityBrowserDriversgeckodriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()

  • 一个新的 rust_mozprofile 在运行时被创建如下:

  • A new rust_mozprofile gets created on the run as follows :

    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 被完全删除/销毁.

  • Of-coarse on a successful closure (i.e. successful invocation of driver.quit()) the temporary rust_mozprofile.xFayqKkZrOB8 gets deleted/destroyed completely.

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

    Again in case of initiating a Browsing Session through an existing Firefox Profile() as follows :

    from selenium import webdriver
    
    myprofile = webdriver.FirefoxProfile(r'C:UsersAtechM_03AppDataRoamingMozillaFirefoxProfilesmoskcpdq.SeleniumTest')
    driver = webdriver.Firefox(firefox_profile=myprofile, executable_path=r'C:UtilityBrowserDriversgeckodriver.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 被删除/销毁完全.

  • Similarly in this case as well on a successful closure (i.e. successful invocation of driver.quit()) the temporary rust_mozprofile.2oSwrQwQoby9 gets deleted/destroyed completely.

    也许根据您的问题时间跨度,要复制的个人资料(例如 >30 分钟) 纯粹是开销.因此,如果不复制 rust_mozprofile,就无法使用 Firefox Profile.

    Perhaps as per your question timespan for profile to copy (something like >30 minutes) is a pure overhead. So it won't be possible to use a Firefox Profile without making a copy of rust_mozprofile.

    • Selenium Client 升级到当前级别版本 3.11.0.
    • GeckoDriver 升级到当前的 GeckoDriver v0.20.0 级别.
    • Firefox 版本升级到 Firefox Quantum v59.0.1 级别.
    • 清理您的项目工作区,通过您的 IDE重建您的项目,仅使用所需的依赖项.
    • 使用 CCleaner 工具清除所有操作系统杂事在执行测试套件之后.
    • 如果您的 Firefox 基础版本太旧,请通过 卸载它Revo Uninstaller 并安装 Firefox Quantum 的最新 GA 和发布版本.
    • 执行您的@Test.
    • Upgrade Selenium Client to current levels Version 3.11.0.
    • Upgrade GeckoDriver to current GeckoDriver v0.20.0 level.
    • Upgrade Firefox version to Firefox Quantum v59.0.1 levels.
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
    • If your base Firefox base version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Firefox Quantum.
    • Execute your @Test.

    这篇关于webdriver.FirefoxProfile():是否可以在不复制的情况下使用配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆