【问题标题】:how do i start Chromedriver not with the default profile?如何不使用默认配置文件启动 Chromedriver?
【发布时间】:2014-10-06 13:04:40
【问题描述】:

我正在尝试使用 Chromedriver 和非默认配置文件加载 Chrome。
我正在使用这个 python 代码:

opt = webdriver.ChromeOptions()
chromedriver = r"C:/chromedriver/chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
opt.add_argument(r"user-data-dir=C:\Users\user\AppData\Local\Google\Chrome\User Data\Default_Selenium")
driver = webdriver.Chrome(opt)


但我收到以下错误:

Traceback (most recent call last):
  File "C:\Users\user\workspace\dd\src\start.py", line 29, in <module>
    main()
  File "C:\Users\user\workspace\dd\src\start.py", line 20, in main
    driver = webdriver.Chrome(opt)
  File "C:\Python27\Lib\site-packages\selenium-2.43.0-py2.7.egg\selenium\webdriver\chrome\webdriver.py", line 59, in __init__
    self.service.start()
  File "C:\Python27\Lib\site-packages\selenium-2.43.0-py2.7.egg\selenium\webdriver\chrome\service.py", line 68, in start
    and read up at http://code.google.com/p/selenium/wiki/ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'ChromeDriver executable needs to be available in the path.                 Please download from http://chromedriver.storage.googleapis.com/index.html                and read up at http://code.google.com/p/selenium/wiki/ChromeDriver' 

我做错了什么?

【问题讨论】:

    标签: python google-chrome selenium selenium-webdriver chrome-web-driver


    【解决方案1】:

    chromedriver 可执行文件应该在PATH 环境变量中可用,或者通过executable_path 参数显式设置为Chrome()

    driver = webdriver.Chrome(executable_path=r'C:/chromedriver/chromedriver.exe',
                              chrome_options=opt)
    

    【讨论】:

    • 我知道它应该这样工作。但我需要加载另一个配置文件。你知道怎么做吗?
    • @Benaya 当然,在chrome_options 参数中传递它,查看更新的答案。
    • 谢谢。现在在列表中它不会崩溃。但是当浏览器启动时,没有加载此配置文件的扩展。我在这里错过了什么?
    • 可以通过vs吗?
    • 投反对票?答案有什么问题,如何改进?
    猜你喜欢
    • 2016-07-25
    • 1970-01-01
    • 2018-12-18
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    • 2021-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多