#python #selenium #ubuntu #selenium-webdriver #firefox
#питон #селен #ubuntu #селен-веб-драйвер #браузер Firefox
Вопрос:
Я установил путь к недавно созданному профилю Firefox в Ubuntu, используя python и Selenium. Но когда я запускаю скрипт на 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/")
Комментарии:
1. у вас все в сообщении об ошибке:
DeprecationWarning: firefox_profile has been deprecated, please use an Options object
. Поэтому вы должны использоватьOptions()
вместоFirefoxProfile()
. Или, может быть, скорееFirefoxOptions()
Ответ №1:
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)
, чтобы просмотреть все параметры с описаниями.