正如文档所述,you can call webdriver.FirefoxProfile()带有 profile_directory
的可选参数指向您希望浏览器使用的特定配置文件的目录。我注意到运行这个命令需要很长时间,所以当我查看代码时,它看起来像是在复制指定的配置文件 问题是,配置文件复制需要很长时间(大约 >30 分钟,没有耐心等待它完成。)
我正在使用用户脚本和 selenium 的混合体来为我做一些自动化,所以每次我想测试我的代码时都设置一个新的配置文件会很麻烦。
是更改此行为以编辑 firefox_profile.py
的唯一方法本身(如果是这样,最好的方法是什么?)?
最佳答案
根据当前使用 FirefoxProfile()
在 Firefox 中实现的 GeckoDriver工作原理如下:
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()
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 被完全删除/销毁。 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()
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 配置文件。 .解决方案
@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/