selenium中的常见报错

时间:2022-11-30 20:21:43

1.

ImportError: cannot import name ‘webdriver'
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH.

Please see https://sites.google.com/a/chromium.org/chromedriver/home原因是由于没有将chromedriver.exe放在/usr/bin/目录里

在导入是要注意:

selenium中的常见报错

第四行
driver = webdriver.Chrome(r"/usr/bin/chromedriver”) 
中应该是chromedrive.exe的路径

2.

======================================================================
ERROR: test_search_in_python_org (__main__.mytest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "mystyle.py", line 12, in test_search_in_python_org
    driver.get("www.baidu.com")
  File "/Users/zhangjia/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 309, in get
    self.execute(Command.GET, {'url': url})
  File "/Users/zhangjia/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 297, in execute
    self.error_handler.check_response(response)
  File "/Users/zhangjia/anaconda/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot navigate to invalid URL"}
  (Session info: chrome=61.0.3163.100)
  (Driver info: chromedriver=2.32.498537 (cb2f855cbc7b82e20387eaf9a43f6b99b6105061),platform=Mac OS X 10.12.6 x86_64)
----------------------------------------------------------------------
Ran 1 test in 1.896s
FAILED (errors=1)

错误原因:

selenium中的常见报错

第十二行应该是http://www.baidu.com不是www.baidu.com