• python selenium模块使用出错-selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.


    Python 2.7+selenium+Firefox 55.0.3

    代码:

    from selenium import webdriver
    from selenium.common.exceptions import NoSuchElementException
    from selenium.webdriver.common.keys import Keys
    import time
    
    browser = webdriver.Firefox() # Get local session of firefox
    browser.get("http://www.yahoo.com") # Load page
    assert "Yahoo!" in browser.title
    elem = browser.find_element_by_name("p") # Find the query box
    elem.send_keys("seleniumhq" + Keys.RETURN)
    time.sleep(0.2) # Let the page load, will be added to the API
    try:
        browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]")
    except NoSuchElementException:
        assert 0, "can't find seleniumhq"
    browser.close()

    错误信息如下:

    selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

    回答摘自知乎:https://www.zhihu.com/question/49568096

    1. selenium 3.x开始,webdriver/firefox/webdriver.py的__init__中,executable_path="geckodriver";而2.x是executable_path="wires"
    2. firefox 47以上版本,需要下载第三方driver,即geckodriver;在的Third Party Drivers, Bindings, and Plugins下面找到Mozilla GeckoDriver,下载到任意电脑任意目录(Mac 下放到了/usr/bin/ 和/sbin/, /bin/,/usr/local/bin/),解压后将该路径加入到PC的path(针对windows)即可。


    作者:iceblue iceblue
    链接:https://www.zhihu.com/question/49568096/answer/119324584
    来源:知乎
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    谷歌浏览器禁止缩放和全面屏显示
    常用正则表达式
    封装时间函数
    年月日,时分秒,星期
    昨天,明天,月初,月末,最近七天,最近一个月,今天零时js
    React框架
    javaweb基础备忘
    一些java基础知识的备忘
    查看deepin版本
    java中堆栈的一些理解备忘
  • 原文地址:https://www.cnblogs.com/v-BigdoG-v/p/7851709.html
Copyright © 2020-2023  润新知