実行するとエラーになります。
「ImportError: cannot import name 'webdriver'」
どうしたらいいでしょうか?
script
test_ut.py (unittest実行用)
python
import unittest import selenium.webtest1 def suite(): suite = unittest.TestSuite() suite.addTest(selenium.webtest1('TestCase1')) return suite if __name__ == '__main__': runner = unittest.TextTestRunner() test_suite = suite() runner.run(test_suite)
selenium/webtest1.py (selenium実行ファイル)
python
# -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoAlertPresentException import unittest, time, re, datetime, os class TestCase1(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) self.base_url = "https://yahoo.co.jp/" self.verificationErrors = [] self.accept_next_alert = True def test_untitled_test_case(self): driver = self.driver driver.get("https://yahoo.co.jp") print(driver.title) def tearDown(self): self.driver.quit() self.assertEqual([], self.verificationErrors) if __name__ == "__main__": unittest.main()
単体での実行結果
python
# python36 selenium/webtest1.py Yahoo! JAPAN . ---------------------------------------------------------------------- Ran 1 test in 2.544s OK
それをimportしたunittest側の実行結果
# python36 test_ut.py Traceback (most recent call last): File "test_ut.py", line 2, in <module> import selenium.webtest1 File "/ababa/selenium/webtest1.py", line 2, in <module> from selenium import webdriver ImportError: cannot import name 'webdriver'
moduleとして実行しても変わらず
# python36 -m test_ut Traceback (most recent call last): File "/usr/lib64/python3.6/runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code exec(code, run_globals) File "/ababa/test_ut.py", line 2, in <module> import selenium.webtest1 File "/ababa/selenium/webtest1.py", line 2, in <module> from selenium import webdriver ImportError: cannot import name 'webdriver'
環境
python 3.6
centos7
まだ回答がついていません
会員登録して回答してみよう