简体   繁体   English

Python Selenium 在 Z1D41C853AF58D3A7AE54990CE294 中设置 firefox 配置文件的路径

[英]Python Selenium setting path to firefox profile in ubuntu

I have set the path to a newly created Firefox profile in Ubuntu using python & Selenium.我已经使用 python 和 ZC49DFB55F086BB406E2ZCAF7 在 Ubuntu 中设置了新创建的 Firefox 配置文件的路径。 But when I run the python script I am getting this problem但是当我运行 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,

This is my python script:这是我的 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 are changing and Selenium also changes some settings - and now old methods are deprecated but still can work (it was only warning, not error). Browsers正在改变, Selenium也改变了一些设置 - 现在旧方法已被弃用但仍然可以工作(这只是警告,而不是错误)。

But warning shows that preferred method is to use Option() instead of FirefoxProfile()但警告显示首选方法是使用Option()而不是FirefoxProfile()

And it doesn't need to use DesiredCapabilities.FIREFOX which adds它不需要使用DesiredCapabilities.FIREFOX添加

{'browserName': 'firefox', 'marionette': True, 'acceptInsecureCerts': True}

because it has it automatically in options.capabilities因为它自动在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")

BTW: you can use help(options) to see all options with descriptions.顺便说一句:您可以使用help(options)查看所有带有说明的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM