代码如下:
from selenium import webdriver
driver =webdriver.Chrome()
在命令行中输入这几行,可以运行成功,但在sublime中运行不成功,错误如下:
Traceback (most recent call last):
File "/Users/zhangyinan/Desktop/test.py", line 5, in
driver =webdriver.Chrome()
File "/Library/Python/2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 61, in init
self.service.start()
File "/Library/Python/2.7/site-packages/selenium/webdriver/common/service.py", line 69, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Exception AttributeError: "'Service' object has no attribute 'process'" in > ignored
[Finished in 0.1s with exit code 1]
在命令行中输入:python /Users/zhangyinan/Desktop/test.py 也可以运行成功。
chromedriver放在桌面上,/Users/zhangyinan/Desktop也加入到环境变量path中。
但是以下这中方式可以运行成功:
from selenium import webdriver
path="/Users/zhangyinan/Desktop/chromedriver"
driver =webdriver.Chrome(path)