webdriver.FirefoxProfile():是否可以不复制配置文件就使用配置文件? [英] webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?
问题描述
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.)
我正在使用用户脚本和硒的混合为我做一些自动化,因此每次我想测试我的代码时都要设置一个新的配置文件会很麻烦.
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配置文件发起浏览会话的情况,如下所示:
If case of initiating a Browsing Session through a new Firefox Profile as follows :
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 ,如下所示:
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:\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 ,如下所示:
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 Client 升级到当前级别 版本3.11.0 .
- 将 GeckoDriver 升级到当前的 GeckoDriver v0.20.0 > 级.
- 将 Firefox 版本升级到 Firefox Quantum v59.0.1 级别. 通过 IDE
- 清理您的项目工作区和重建您的项目,并且仅具有必需的依赖项.
- 使用 CCleaner 工具清除之前和之后的所有操作系统杂项在执行 test Suite 之后.
- 如果您的基本 Firefox 基本版本太旧,请通过卸载它 Revo Uninstaller 并安装最新版本的 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屋!