With the code:

from selenium import webdriver from selenium.webdriver.firefox.options import Options options = Options.add_argument('-headless') browser = webdriver.Firefox(options) browser.get('https://www.youtube.com/') browser.implicitly_wait(50) browser.find_element_by_css_selector('ytd-button-renderer.ytd-masthead:nth-child(4) > a:nth-child(1) > paper-button:nth-child(1)').click() print('Нажала.Что дальше, изволите?') browser.close() 

I get an error:

Error: - TypeError: add_argument () missing 1 required positional argument: 'argument'

    2 answers 2

    In the Options class, the add_argument() method is defined as :

     def add_argument(self, argument): """Add argument to be used for the browser process.""" if argument is None: raise ValueError() self._arguments.append(argument) 

    As you can see:

    1. This method has 2 arguments: self and argument .
    2. This method does not return anything meaningful (and so returns None ), and so it does not make sense to save its result (in some variable).

    Your code

     options = Options.add_argument('-headless') 

    on the right page, it applies the add_argument() method directly to the Options class , and so it expects these 2 arguments ( self and argument ), but you provide only 1 ( '-headless' ), and so the second argument is not available.

    But the add_argument() method is not a class method — it is not intended to be applied to an object . This is evident from the name self for the first argument. When applying a method to an object ( Options class), the self argument is not given - it will be automatically (implicitly) filled with a reference to the object that the method called. Simply

     имя_объекта.add_argument('-headless') 

    perhaps understood as

     add_argument(имя_объекта, '-headless') 

    From this it follows that you need an object of the class Options, which you will directly modify by the add_argument() method and then use it as a parameter instead of

     options = Options.add_argument('-headless') browser = webdriver.Firefox(options) 

    (in your code) use (as you called your options variable) this code:

     options = Options() options.add_argument('-headless') browser = webdriver.Firefox(firefox_options=options) 

      To solve it, it was necessary to create a Options object first and only then add the necessary argument.

       # Создаём объект options = Options() # Добавляем аргумент options.add_argument('-headless') browser = webdriver.Firefox(firefox_options=options)