繁体   English   中英

使用命令行选项运行selenium Webdriver时出现python异常

[英]python exception when running selenium webdriver with command line options

我有以下这段代码来调用带有扩展名的chrome浏览器:

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

当我执行这段代码时,我得到以下堆栈跟踪:

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?

使用以下代码:

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

path_to_extension = str(path_to_extension)

选项= webdriver.ChromeOptions()

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

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

self._wd.create_options()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM