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

1 Answer 1

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) 
Sign up to request clarification or add additional context in comments.

3 Comments

now it shows this error - TypeError: listdir: path should be string, bytes, os.PathLike or None, not Options
Check my update. You should really follow some python guides and some selenium tutorials, as the errors that you make are very basic.
yeah i am learning & reading but some errors i don't understand. Thank you it is working now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.