0

I am just trying to run this using headless browser i don't understand why it keeps throwing me the error even if i have provided argument. Here i have read that it requires argument to pass in options.add_argument() :- https://seleniumhq.github.io/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.options.html#module-selenium.webdriver.firefox.options

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

from selenium import webdriver
from selenium.webdriver.firefox.options import Options


options = Options.add_argument('-headless')
browser = webdriver.Firefox(options)
browser.get('https://intoli.com/blog/email-spy/')
browser.implicitly_wait(50)
heading = browser.find_element_by_xpath('//*[@id="heading-breadcrumb"]/div/div/div/h1').text
print(heading)
browser.close()
Rahul
  • 49
  • 6

1 Answers1

2

You should create an object Options before calling the property on it. For more informations about how @property works, see this answer.

# create a new object
options = Options()
# calling the property (setter)
options.add_argument('-headless')

Update : Furthermore, it seems that there are other problems with your code sample. If you want to provide only firefox_options, you should do it as a keyword argument, so you must provide it explicitly:

browser = webdriver.Firefox(firefox_options=options) 
Lescurel
  • 10,749
  • 16
  • 39
  • now it shows this error - TypeError: listdir: path should be string, bytes, os.PathLike or None, not Options – Rahul Sep 07 '17 at 10:10
  • Check my update. You should really follow some python guides and some selenium tutorials, as the errors that you make are very basic. – Lescurel Sep 07 '17 at 10:27
  • yeah i am learning & reading but some errors i don't understand. Thank you it is working now – Rahul Sep 07 '17 at 10:38