Python版本相关的错误

时间:2015-09-15 12:43:21

标签: python-3.x selenium webdriver

我正在尝试使用Selenium webdriver库HTMLTestRunner生成HTML测试报告。我正在使用Python 3.4版本,我有一个版本相关的错误。请参阅以下摘录。

import unittest`enter code here`
import HTMLTestRunner
from selenium import webdriver
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.keys import Keys

class GreenlamTest(unittest.TestCase):

    @classmethod
    def setUp(cls):
        cls.driver=webdriver.Firefox()
        cls.driver.implicitly_wait(30)
        cls.driver.maximize_window()
        cls.driver.get('https://www.google.co.in')

    def test_checkTitle(self):
        assert "Google" in self.driver.title

    def test_searchtest(self):
        driver = self.driver
        elem = self.driver.find_element_by_name("q")
        elem.send_keys("pycon")
        elem.send_keys(Keys.RETURN)

    @classmethod   
    def tearDown(cls):
    cls.driver.quit()


if __name__ == '__main__':
    HTMLTestRunner.main

输出

Finding files... done.
Traceback (most recent call last):
  File "C:\Users\vaibhav\Desktop\Selenium Softwares\eclipse-jee-luna-SR2-win32-x86_64\eclipse\plugins\org.python.pydev_4.0.0.201504132356\pysrc\pydev_runfiles.py", line 468, in __get_module_from_str
    mod = __import__(modname)
  File "C:\Users\vaibhav\Desktop\Selenium Softwares\Practice\pythondemo\Htmlreport.py", line 2, in <module>
    import HTMLTestRunner
  File "C:\Users\vaibhav\Desktop\Selenium Softwares\Practice\pythondemo\HTMLTestRunner.py", line 94, in <module>
    import StringIO
ImportError: No module named 'StringIO'
ERROR: Module: Htmlreport could not be imported (file: C:\Users\vaibhav\Desktop\Selenium Softwares\Practice\pythondemo\Htmlreport.py).
Importing test modules ... done.

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

1 个答案:

答案 0 :(得分:0)

您收到错误,因为您的文件夹名称Selenium Softwares在其中存在Htmlreport的位置。替换文件夹名称以排除其中的空格,可能是下划线或camelCase等...像这样Selenium_Softwares。这是怎样的 -

file: C:\Users\vaibhav\Desktop\Selenium_Softwares\Practice\pythondemo\Htmlreport.py)

希望这有帮助。