python - 如何让 Selenium 直接在现有的 Firefox 配置文件上运行?
问题描述
我发现即使我指定:
webdriver.Firefox(
firefox_profile=webdriver.FirefoxProfile("/my/profile/path")
)
Selenium 实际上会克隆该配置文件并基于该临时克隆启动浏览器。当您使用 Selenium 进行测试时,我确信这是有道理的,但是当我将它用于自动化时,我想直接在现有配置文件上进行操作。
这对 Selenium 可行吗?实际上,我正在寻找一种方法来维护会话之间的状态(书签、历史记录、Firefox 同步设置等),因此持久会话对我来说最有意义。我在 Python 中做这项工作,但我想其他语言中使用的模式会是相似的。
解决方案
尝试这个
from selenium import webdriver
myprofile = webdriver.FirefoxProfile(r'C:\Users\{YOUR OWN USERNAME}\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()
确保您使用正确的配置文件路径!
推荐阅读
- audio - 将大量音频文件混合成立体声
- angular - 角度上传图片到服务器
- spring - Mockito @Spy 在定义模拟行为时调用真实方法
- git - Gitlab仓库,重写文件
- reporting-services - SSRS 显示 n/a 时 n/a
- oracle - 从一个字段 PLSQL 进行多值搜索
- excel - 识别图像名称
- inno-setup - 我可以使用 Inno Setup 预处理器在 isl 文件中决定哪些消息引用哪个安装程序吗?
- c - write() 到 sysfs 条目 /sys/bus/pci/devices/.../driver/remove_id 失败
- php - Gmail SMTP 返回 250 OK,但 Codeigniter 遇到错误