【问题标题】:Python Selenium Testing with unittest - driver error使用 unittest 进行 Python Selenium 测试 - 驱动程序错误
【发布时间】:2018-10-12 16:03:56
【问题描述】:

尝试在 python 和 selenium 中运行测试,我得到了 Attribute 错误:对象没有属性驱动程序'。我哪里错了? 错误如下。修剪了代码。问题在于 test_selenium 函数的设置和前 4 或 5 行

        ======================================================================
        ERROR: test_selenium (__main__.Servicenow_IncCreate)
        ----------------------------------------------------------------------
        Traceback (most recent call last):
          File "C:/firefox_inccreate_cloudv2.py", line 27, in test_selenium
            driver = self.driver
        AttributeError: 'Servicenow_IncCreate' object has no attribute 'driver'

        ----------------------------------------------------------------------
        Ran 1 test in 0.011s

        FAILED (errors=1)

        The Python code is - >

        from selenium import webdriver
        import time
        from selenium.webdriver.common.keys import Keys
        from selenium.webdriver.support import expected_conditions as EC
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support.ui import WebDriverWait
        from selenium.webdriver.support.ui import Select
        from datetime import date
        from selenium.webdriver.common.action_chains import ActionChains
        import unittest

        class Servicenow_IncCreate(unittest.TestCase):
            def setup(self):
                self.driver = webdriver.Firefox()

            def test_selenium(self):    
                # 
                today = str(date.today())
                base_url =  "xxx"
                driver = self.driver
                driver.get(base_url)


                driver.switch_to_frame("gsft_main")
                username = driver.find_element_by_id("xxxx")
                username.send_keys("admin")

                password = driver.find_element_by_id("user_password")
                password.send_keys("xxxx")
                password.send_keys(Keys.RETURN)


            def teardown(self):
                self.driver.close()         

        if __name__ == '__main__':
            unittest.main()

【问题讨论】:

    标签: python selenium python-unittest


    【解决方案1】:

    没关系,必须使用 setUp 而不是 setup...已回答

    【讨论】:

      猜你喜欢
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 2021-09-20
      • 1970-01-01
      相关资源
      最近更新 更多