Anu
Anu

Reputation: 21

Selenium invalid arg exeption

I made a class as the basic setup of the selenium driver. when I run it, I receive an error message called 'invalid argument' I do not what to do.

I think it's an error with my tuple 'url' in this code. please help me.

class SeleniumDriver: '''basic setup for chromedriver(selenium)'''

def __init__(self, 
             driversource='C:\\Users\Ewis\Downloads\chromedriver.exe',
             url = ('https://realpython.com/')
             ):
    self.driversource = driversource
    self.url = url # this tuple

def __enter__(self):
    self.driver = webdriver.Chrome(executable_path=self.driversource)
    for urls in self.url:
        self.driver.get(urls)
    return self.driver, Keys

def __exit__(self, exc_type, exc_val, exc_trace):
    self.driver.quit()

Traceback (most recent call last):

 File "<stdin>", line 1, in <module>
  File "c:\python\progs\my_modules\seleniumdriver\seleniumdriver.py", line 16, in __enter__
    resp = self.driver.get(urls)
  File "C:\python\python run 3.7.3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "C:\python\python run 3.7.3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\python\python run 3.7.3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
  (Session info: chrome=75.0.3770.100)

Upvotes: 1

Views: 677

Answers (1)

holdenweb
holdenweb

Reputation: 37023

Welcome to Stackoverflow. The likely fault is that you aren't passing a tuple as the url argument. the correct form would be

    def __init__(self, 
                 driversource='C:\\Users\Ewis\Downloads\chromedriver.exe',
                 url = ('https://realpython.com/', )
                 ):
        self.driversource = driversource
        self.url = url # this tuple

Without the almost unnoticeable extra comma your default url argument is simply a parenthesised string.

Upvotes: 1

Related Questions