[英]Python Firefox Selenium Load Profile
I tried many combinations of Geckodrive,Selenium and Python but i could not achieved to load Firefox profile what i need.It loads the default profile.我尝试了 Geckodrive、Selenium 和 Python 的许多组合,但我无法加载我需要的 Firefox 配置文件。它加载了默认配置文件。 The lastest code is below and I opened an issue on github Selenium page but there is still no solution.There are some solutions about Java but I am not able to bind it in Python.A temp file created on temp folder which includes profile data and cookies.That mean selenium does not use any profile's cookies and other configurations最新代码如下,我在 github Selenium 页面上打开了一个问题,但仍然没有解决方案。有一些关于 Java 的解决方案,但我无法在 Python 中绑定它。在临时文件夹上创建的临时文件包含配置文件数据和cookies。这意味着 selenium 不使用任何配置文件的 cookie 和其他配置
Any solutions will be apprecited.任何解决方案都会受到赞赏。
Geckodrive version:0.23 Selenium 3.14 Python 3.7 Firefox 61 Geckodrive 版本:0.23 Selenium 3.14 Python 3.7 Firefox 61
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.support.ui import WebDriverWait
fp = FirefoxProfile('C:\\Users\\<USER>\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\ji8rbij6.test')
fp.update_preferences()
browser = webdriver.Firefox(firefox_profile=fp)
Thanks in advance提前致谢
PS. PS。 I tried this code block in 3 different computer because of being able to have a problem on my own computer由于能够在我自己的计算机上出现问题,我在 3 台不同的计算机上尝试了此代码块
This exact setup works as expected for me (windows10) and I'm able to load custom firefox profiles.这个确切的设置对我来说可以正常工作(windows10),我可以加载自定义的 firefox 配置文件。 Firefox: 88.0.1 Geckodriver: 0.30.0 ( geckodriver releases Python: 3.8.10 robotframework-selenium2library: 3.0.0 robotframework-seleniumlibrary: 6.0.0 Firefox:88.0.1 Geckodriver:0.30.0( geckodriver 发布Python:3.8.10 robotframework-selenium2library:3.0.0 robotframework-seleniumlibrary:6.0.0
import SeleniumLibrary
from selenium import webdriver
from robot.libraries.BuiltIn import BuiltIn
def create_profile(self)
fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.folderList", 2)
fp.set_preference("browser.download.manager.showWhenStarting", False)
fp.set_preference("browser.download.panel.shown", False)
fp.set_preference("browser.download.dir","**provide_download_dir_here**")
fp.set_preference("browser.helperApps.neverAsk.openFile",
"application/zip,application/octet-stream, application/x-zip-compressed,
multipart/x-zip,image/jpeg,application/xml,application/pdf,text/plain,text/csv,
*/*")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk",
"application/zip,application/octet-stream, application/x-zip-compressed,
multipart/x-zip,image/jpeg,application/xml,application/pdf,text/plain,text/csv,
*/*")
fp.update_preferences()
return fp.path
# Add the following code where you open the browser
ff = self.create_profile()
BuiltIn().get_library_instance("SeleniumLibrary").open_browser("https://your_url","F irefox",ff_profile_dir=ff)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.