webdriver.FirefoxProfile():是否可以使用配置文件而不复制它? [英] webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?
问题描述
正如文档所述,您可以使用 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?)?
推荐答案
根据当前实现的 GeckoDriver 与 Firefox 使用 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 在运行时被创建如下:
Similarly a new rust_mozprofile gets created on the run as follows :
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 配置文件.
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 客户端 升级到当前级别 版本 3.11.0强>.
- 将 GeckoDriver 升级到当前 GeckoDriver v0.20.0 级别.
- 将 Firefox 版本升级到 Firefox Quantum v59.0.1 级别.
- 清理你的项目工作区通过你的IDE和重建你的项目只需要依赖.
- 使用 CCleaner 工具清除之前和在您的测试套件执行之后.
- 如果您的基础 Firefox 基础版本太旧,请通过 卸载它Revo Uninstaller 并安装最新的 GA 和发布版本的 Firefox Quantum.
- 执行你的
@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屋!