TA的每日心情 | 慵懒 2017-10-26 16:47 |
---|
签到天数: 56 天 连续签到: 1 天 [LV.5]测试团长
|
用unittest 写的小框架,最后报错“AttributeError: 'ceshi' object has no attribute 'driver' ” ,但是检查了好多次,明明已经定义属性了,为什么还会报错
代码如下:
#encoding:utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.support.select import Select
import unittest,time,os
class ceshi(unittest.TestCase):
def setUP(self):
self.driver = webdriver.Firefox()
self.driver.get("http://5.inuoer.com/admin")
self.verificationErrors = []
self.accept_next_alert = True
def test_ceshi(self):
driver = self.driver
time.sleep(2)
driver.find_element_by_name("username").send_keys("admin")
driver.find_element_by_name("password").send_keys("admin")
time.sleep(2)
driver.find_element_by_class_name("loginBtn").submit()
time.sleep(3)
driver.switch_to_frame("menu")
driver.find_element_by_link_text(u"添加信息").click()
time.sleep(2)
driver.switch_to_default_content()
driver.switch_to_frame("main")
xz = driver.find_element_by_id("classid")
Select(xz).select_by_value('15') # 企业网站
time.sleep(2)
driver.find_element_by_id("title").send_keys(u"名字")
driver.find_element_by_xpath("//input[@value='a']").click()
driver.find_element_by_id("source").send_keys("moijkgoij")
ff = driver.find_element_by_xpath("//div/iframe[@class='ke-edit-iframe']")
driver.switch_to_frame(ff)
time.sleep(2)
driver.find_element_by_class_name("ke-content").send_keys(
u"selenium是浏览器测试的大杀器,在研究ajax数据抓取时碰巧研究了一下")
driver.switch_to.parent_frame()
driver.find_element_by_class_name("submit").submit()
driver.switch_to_default_content()
time.sleep(2)
def is_element_present(self, how, what):
try:self.driver.find_element(by=how, value=what)
except NoSuchElementException as e : return False
return True
def is_alert_present(self):
try:self.driver.switch_to_alert()
except NoAlertPresentException as e : return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accppt()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
报错截图:
|
|