selenium+python报错:attributrerror,请指教!
错误提示:ERROR: test_baidu_set (__main__.Baidu)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\Files\baidu-2.py", line 48, in tearDown
self.assertEqual([],self.verificationErrors)
AttributeError: 'Baidu' object has no attribute 'verificationErrors'
----------------------------------------------------------------------
Ran 2 tests in 32.522s
FAILED (errors=2)
脚本:
#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
import unittest, time, re
class Baidu(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.baidu.com/"
self.verificationErrors = []
self.accept_next_alert = True
#百度搜索用例
def test_baidu_search(self):
driver=self.driver
driver.get(self.base_url+"/")
driver.find_element_by_id("kw").send_keys("selenium webdriver")
driver.find_element_by_id("su").click()
time.sleep(2)
driver.close()
#百度设置用例
def test_baidu_set(self):
driver=self.driver
#进入搜索设置页
driver.get(self.base_url+"/gaoji/preferences.html")
#设置每页搜索结果为100条
m=driver.find_element_by_name("NR")
m.find_element_by_xpath("//option[@value='50']").click()
time.sleep(2)
#保存设置的信息
driver.find_element_by_xpath("/html/body/form/div/input").click()
time.sleep(2)
#driver.switch_to_alert().accept()
alert=driver.switch_to_alert()
print(alert.text)
alert.accept()
def tearDown(self):
self.driver.quit()
self.assertEqual([],self.verificationErrors)
if __name__=="__main__":
unittest.main()
这个脚本在我这运行正常,是不是你的执行什么其他异常操作?
这个错误是指属性错误,指 'Baidu' 这个对象没有'verificationErrors'这个属性。
AttributeError: 'Baidu' object has no attribute 'verificationErrors' 若尘_51 发表于 2016-10-10 08:42
这个脚本在我这运行正常,是不是你的执行什么其他异常操作?
这个错误是指属性错误,指 'Baidu' 这个 ...
谢谢!已找到问题所在,同一目录下有多个名称相同的文件 解决了就好。:lol
页:
[1]