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

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

问题描述

文档说明中,

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.

    • 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天全站免登陆