'python exception when running selenium webdriver with command line options

I have this following piece of code to invoke a chrome browser with an extension:

    path_to_extension = path.abspath(r'C:\temp\ublock_extension_1_21_6_0.crx')
    path_to_extension = str(path_to_extension)
    chrome_options = Options()
    chrome_options.add_argument(str('load-extension=') + path_to_extension)

    self._wd = webdriver.Chrome(chrome_options)
    self._wd.create_options()

When I execute this piece of code, I get the following stack trace:

Traceback (most recent call last):
  File "seleniumtest.py", line 43, in __init__
    self._wd = webdriver.Chrome(chrome_options)
  File "c:\python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "c:\python27\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "c:\python27\lib\subprocess.py", line 394, in __init__
    errread, errwrite)
  File "c:\python27\lib\subprocess.py", line 599, in _execute_child     
    args = list2cmdline(args)
  File "c:\python27\lib\subprocess.py", line 266, in list2cmdline       
    needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'Options' is not iterable```

It looks like passing chrome options to the selenium webdriver seems to croak the subprocess. Any idea how I can fix this?


Solution 1:[1]

Use the following code :

path_to_extension = path.abspath(r'C:\temp\ublock_extension_1_21_6_0.crx')

path_to_extension = str(path_to_extension)

options = webdriver.ChromeOptions()

options.add_argument(str('load-extension=') + path_to_extension)

self._wd = webdriver.Chrome(options=options)

self._wd.create_options()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1