我已经使用 python 和 Selenium 在 Ubuntu 中设置了新创建的 Firefox 配置文件的路径。但是当我运行 python 脚本时,我遇到了这个问题
/bin/python3 /home/frixreda/Desktop/Python/testU.py
/home/frixreda/Desktop/Python/testU.py:7: DeprecationWarning: firefox_profile has been deprecated, please use an Options object
profile = webdriver.FirefoxProfile(
/home/frixreda/Desktop/Python/testU.py:13: DeprecationWarning: capabilities and desired_capabilities have been deprecated, please pass in a Service object
driver = webdriver.Firefox(firefox_profile=profile,
/home/frixreda/Desktop/Python/testU.py:13: DeprecationWarning: firefox_profile has been deprecated, please pass in an Options object
driver = webdriver.Firefox(firefox_profile=profile,
这是我的python脚本:from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
profile = webdriver.FirefoxProfile(
r'/home/frixreda/.mozilla/firefox/3uz1obam.default')
profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
profile.update_preferences()
desired = DesiredCapabilities.FIREFOX
driver = webdriver.Firefox(firefox_profile=profile,
desired_capabilities=desired)
driver.get("https://gmail.com/")
最佳答案
Browsers
正在改变和Selenium
还更改了一些设置 - 现在不推荐使用旧方法但仍然可以工作(这只是警告,而不是错误)。
但警告显示首选方法是使用 Option()
而不是 FirefoxProfile()
并且不需要使用DesiredCapabilities.FIREFOX
这增加了
{'browserName': 'firefox', 'marionette': True, 'acceptInsecureCerts': True}
因为它自动在 options.capabilities
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
#from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
options = Options()
#help(options)
options.add_argument('-profile')
options.add_argument('/home/frixreda/.mozilla/firefox/3uz1obam.default')
options.set_preference('dom.webdriver.enabled', False)
options.set_preference('useAutomationExtension', False)
#options.set_headless() # deprecated
#options.headless = True # preferred
#options.set_capability(name, value)
#print("DesiredCapabilities:", DesiredCapabilities.FIREFOX) # {'browserName': 'firefox', 'marionette': True, 'acceptInsecureCerts': True}
print('accept_insecure_certs:', options.accept_insecure_certs)
print('arguments :', options.arguments)
print('preferences :', options.preferences)
print('capabilities:', options.capabilities)
print('headless :', options.headless)
print('profile :', options.profile) # `None`??? but browser uses profile
print('proxy :', options.proxy)
print('binary :', options.binary)
#print('binary_location:', options.binary_location)
print('log :', options.log)
driver = webdriver.Firefox(options=options)
#driver.get("https://stackoverflow.com")
driver.get("https://gmail.com")
顺便说一句:您可以使用
help(options)
查看所有带有说明的选项。
关于Python Selenium在ubuntu中设置firefox配置文件的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70272235/