尝试在python和selenium中运行测试,我正在获取属性 错误:对象没有属性驱动程序。我要去哪里错了? 错误如下。整理代码。问题在于设置和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()
答案 0 :(得分:0)
没关系,必须使用setUp而不是setup ... answered