简体   繁体   中英

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. But when I run the python script I am getting this problem

/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:

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).

But warning shows that preferred method is to use Option() instead of FirefoxProfile()

And it doesn't need to use DesiredCapabilities.FIREFOX which adds

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

because it has it automatically in 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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