【问题标题】:Can I still specify a path to chromedriver using ChromeOptions in Python?我仍然可以在 Python 中使用 ChromeOptions 指定 chromedriver 的路径吗?
【发布时间】:2017-04-13 02:25:59
【问题描述】:

我收到此错误:“WebDriverException:消息:'chromedriver' 可执行文件需要在 PATH 中。” 我能够修复它的唯一方法是手动添加 chromedriver 的位置之一,如下所示:

driver = webdriver.Chrome("/Users/anncolvin/.rvm/bin/chromedriver")

Chrome 启动后,我收到此错误:“您正在使用不受支持的命令行标志:--ignore-certifcate-errors。稳定性和安全性将受到影响。”

我想尝试使用以下代码来解决这个新错误,但我不知道如何/是否可以将它与手动指定 chromedriver 的位置相结合?

options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["ignore-
certificate-errors"])
browser = webdriver.Chrome(chrome_options=options)
browser.get("http://google.com/")

【问题讨论】:

    标签: python command-line path selenium-chromedriver chrome-options


    【解决方案1】:

    您所要做的就是在调用 Chrome 网络驱动程序时指定网络驱动程序位置作为参数,如下所示:

    chrome_path = r"/Users/anncolvin/.rvm/bin/chromedriver"
    browser = webdriver.Chrome(chrome_path, chrome_options=options)
    

    【讨论】:

    • 你能说出路径中的'r'是什么吗:r"/Users/anncolvin/.rvm/bin/chromedriver"
    • @Snedden27 它只是意味着它是一个string literal
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    • 1970-01-01
    • 2023-01-11
    • 2011-06-26
    • 2017-06-01
    • 2012-04-29
    • 2013-01-11
    相关资源
    最近更新 更多