Python:我需要在我的程序目录中包含哪些模块来运行Selenium和Unittest?

时间:2014-07-25 08:31:16

标签: python google-chrome selenium browser webdriver

我正在尝试使用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.pyselenium.py。有什么我想念的吗?或问题完全不同?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我也面临同样的问题,我确实喜欢这个

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)现在运行它会起作用。