当前位置:   article > 正文

python selenuim TypeError: WebDriver.__init__() got an unexpected keyword argument ‘chrome_options‘

typeerror: webdriver.__init__() got an unexpected keyword argument 'chrome_o

Python selenuim TypeError: WebDriver.__init__() got an unexpected keyword argument 'chrome_options'

运行客户端:Pycharm 

运行程序如下:

  1. from selenium import webdriver
  2. from selenium.webdriver.chrome.options import Options
  3. options = Options()
  4. wd = webdriver.Chrome(chrome_options=options, executable_path=r'c:\chromedriver\chromedriver.exe')

Run之后出现的错误如下。

TypeError: WebDriver.__init__() got an unexpected keyword argument 'chrome_options'/'executable_path'

在Anaconda里面是可以运行成功的,所以由此我们查询了其selenium版本。

而此时在Pycharm中,selenium的版本是 4.15.2的新版本,包括urllib3的版本。

解决方案:

一、统一变成低版本 可直接运行代码的版本。

​​​​​​参阅:Selenium |AttributeError: 'WebDriver' object has no attribute 'find_element_by_class_name' - 老表爱技术https://www.cnblogs.com/rychh/p/17146472.html
 

二、维持Pycharm中版本不变,改代码去适应新版本的需求。

  1. import time,os,re
  2. from selenium import webdriver
  3. from selenium.webdriver.common.keys import Keys
  4. from selenium.webdriver.chrome.options import Options
  5. from selenium.webdriver.chrome.service import Service
  6. service = Service(executable_path=r'c:\chromedriver\chromedriver.exe)
  7. options = webdriver.ChromeOptions()
  8. driver = webdriver.Chrome(service=service, options=options)
  9. #......
  10. driver.quit()
  11. 可参阅:
  12. https://stackoverflow.com/questions/76550506/typeerror-webdriver-init-got-an-unexpected-keyword-argument-executable-p

萌新公众号 欢迎关注。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/284707
推荐阅读
相关标签
  

闽ICP备14008679号