0%

Selenium中的常见报错

1.

1
ImportError: cannot import name ‘webdriver'
1
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH
1
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/目录里

在导入是要注意:

这里写图片描述

第四行
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
driver = webdriver.Chrome(r"/usr/bin/chromedriver”) 
```
##### 中应该是chromedrive.exe的路径
---
### 2.
```python
======================================================================
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)

错误原因:

这里写图片描述

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