selenium.webdriver.firefox.options - what is it about? selenium.webdriver.firefox.options - what is it about? selenium selenium

selenium.webdriver.firefox.options - what is it about?


Options is a class in the selenium firefox webdriver package.opts is an instance of the Options class instantiated for the program.

When the code says:

opts = Options()

Python creates an instance of the class, and uses the the variable opts as the access point.

When the code says:

opts.set_headless()

Python is updating the instance of Options, to store the information “the user of this wants to start a headless instance of the browser”

When the code says:

browser = Firefox(options=opts)

Python is creating an instance of the Firefox class, and sending it the opts variable to configure the new instance. In this case, the only option that has been modified from the defaults is the headless flag.


from selenium import webdriverfrom selenium.webdriver.firefox.options import Optionsimport time#--| Setupoptions = Options()options.add_argument("--headless")caps = webdriver.DesiredCapabilities().FIREFOXcaps["marionette"] = Truebrowser = webdriver.Firefox(firefox_options=options, capabilities=caps, executable_path=r"geckodriver.exe")#--| Parsebrowser.get('https://duckduckgo.com')logo = browser.find_elements_by_css_selector('#logo_homepage_link')print(logo[0].text)

this code works ( gives output About DuckDuckGo ). I was told that opts.set_headless() is deprecated, maybe that's why it didn't give me any result.