@data(["abc","123456",True],["abc","1qaz",False])
@unpack
def testLogIn(self,username,password,expectedresult):
self.driver.find_element_by_name(u"请输入用户名/手机号").send_keys(username)
self.driver.find_element_by_name(username).click()
self.driver.find_element_by_xpath("//android.widget.EditText[contains(@NAF,'true')]").send_keys(password)
self.driver.find_element_by_class_name("android.widget.Button").click()
time.sleep(5)
try:
if self.driver.find_element_by_class_name("android.widget.Button").is_displayed():
exist = True
print 11
except Exception, e:
exist = False
print 22
self.assertEqual(exist, expectedresult)
self.driver.find_element_by_xpath("//android.widget.ImageView[contains(@NAF,'true')]").click()
time.sleep(5)
self.driver.find_element_by_name(u"退出登录").click()
self.driver.find_element_by_name(u"确定").click()
def tearDown(self):
self.driver.quit()
是一个登录的,输入错误的用户名 或者密码就报错
======================================================================
ERROR: testLogIn_1___sunxiaofang____123456___True_ (__main__.MyTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\ddt-1.1.1-py2.7.egg\ddt.py", line 139, in wrapper
return func(self, *args, **kwargs)
File "D:\automation\python_test\src\unittestdemo.py", line 46, in testLogIn
self.driver.find_element_by_name(u"退出登录").click()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 365, in find_element_by_name
return self.find_element(by=By.NAME, value=name)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\appium\webdriver\errorhandler.py", line 29, in check_response
raise wde
NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
密码错误不是应该直接关闭么 怎么还要定位元素 多谢 |