selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
----------------------------------------------------------------------
Ran 1 test in 0.014s
FAILED (errors=1)
先检查浏览器版本
再去到 https://sites.google.com/a/chromium.org/chromedriver/home
下载对应的chromedriver版本
解压放到 python安装文件里面去就可以跑动了
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import unittest
from selenium.webdriver.support.wait import WebDriverWait
class Test_web(unittest.TestCase):
def setUp(self):
self.timeout = 40
self.brower = webdriver.Chrome()
self.brower.set_page_load_timeout(self.timeout)
self.wait = WebDriverWait(self.brower,self.timeout)
def tearDown(self):
pass
def test_can_start(self):
self.brower.get('http://10.7.152.104:8080/')
self.assertIn('物业管理',self.brower.title)
login_link = self.wait.until(
EC.element_to_be_clickable((By.LINK_TEXT, '业主登录')))
login_link.click()
if __name__ == '__main__':
unittest.main(warnings='ignore')
还有个笨办法:
把chromedriver放到下面这个路径
C:\Program Files (x86)\Google\Chrome\Application
在代码里面的Chrome()中添加路径就Ok
Chrome(‘C:\Program Files (x86)\Google\Chrome\Application\chromedriver’)
但是这样很麻烦每次写路径