python - 出錯(cuò):Unresolved reference ’selenium’是什么原因
問題描述
# -*- coding: utf-8 -*-from selenium import seleniumimport unittest, time, reclass rc(unittest.TestCase): def setUp(self):self.verificationErrors = []self.selenium = selenium('localhost', 4444, '*chrome', 'https://www.baidu.com/')self.selenium.start()def test_rc(self):sel = self.seleniumsel.open('/')sel.type('id=kw', 'selenium')sel.click('id=container')sel.click('id=su')def tearDown(self):self.selenium.stop()self.assertEqual([], self.verificationErrors)if __name__ == '__main__': unittest.main()
這是用selenium ide 錄的,轉(zhuǎn)成 selenium remote control代碼
在ide測(cè)試是通過的。
但在pycharm里打開,第一行from selenium import selenium
就會(huì)出錯(cuò):Unresolved reference ’selenium’
這是什么原因?
======================================
(我的環(huán)境是python3.5
selenium3.3.1
selenium-server-standalone-3.3.1.jar)
問題解答
回答1:打開Pycharm設(shè)置搜索Project Interpreter查看是否有對(duì)應(yīng)的包,以及Python版本是否和你的Python版本一致
確認(rèn)你的selenium在PYTHONPATH中
添加selenium到你的PYTHONPATH中 or Pycharm依賴中
回答2:這個(gè)問題是由于你的電腦安裝了多個(gè)Python ,解決方法請(qǐng)參考。
https://zhuanlan.zhihu.com/p/...
相關(guān)文章:
1. mysql - 在不允許改動(dòng)數(shù)據(jù)表的情況下,如何優(yōu)化以varchar格式存儲(chǔ)的時(shí)間的比較?2. javascript - Img.complete和img.onload判斷圖片加載完成有什么區(qū)別?3. docker網(wǎng)絡(luò)端口映射,沒有方便點(diǎn)的操作方法么?4. mysql 為什么主鍵 id 和 pid 都市索引, id > 10 走索引 time > 10 不走索引?5. css3 - 純css實(shí)現(xiàn)點(diǎn)擊特效6. java中返回一個(gè)對(duì)象,和輸出對(duì)像的值,意義在哪兒7. 安全性測(cè)試 - nodejs中如何防m(xù)ySQL注入8. javascript - 關(guān)于apply()與call()的問題9. MySQL中無法修改字段名的疑問10. python - 在sqlalchemy中獲取剛插入的數(shù)據(jù)id?
