[英]Python: What modules do I need to include in the directory of my program to run Selenium with Unittest?
我正在嘗試使用Pycharm IDE運行以下代碼:
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = driver.find_element_by_name("q")
elem.send_keys("selenium")
elem.send_keys(Keys.RETURN)
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
我這樣做時會收到以下錯誤:
Traceback (most recent call last):
File "/Users/BigRed/PycharmProjects/python 3/source.py", line 8, in setUp
self.driver = webdriver.Firefox()
AttributeError: 'module' object has no attribute 'Firefox'
在源文件的目錄中,我還有selenium文件夾,其中包含webdriver文件以及exceptions.py
和selenium.py
。 我有什么想念的嗎? 還是問題完全不同?
謝謝你的幫助。
我也遇到同樣的問題,我確實是這樣
1) open terminal (ctrl+alt+t)
2) check $ python --version
3) now install firefox using pip or sudo apt-get
要么
1) open terminal (ctrl+alt+t)
2) check $ python --version (2.7.5....) and
3) In pycharm go to project interpreter and select the same python version as project interpreter.
4)現在運行即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.