簡體   English   中英

Python:要在Unittest中運行Selenium,我需要在程序目錄中包括哪些模塊?

[英]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.pyselenium.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM