51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1885|回复: 3
打印 上一主题 下一主题

帮忙看下多谢

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2017-7-4 15:05:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
@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.

密码错误不是应该直接关闭么 怎么还要定位元素  多谢
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

  • TA的每日心情
    奋斗
    2019-12-31 08:59
  • 签到天数: 975 天

    连续签到: 1 天

    [LV.10]测试总司令

    2#
    发表于 2017-7-4 15:26:28 | 只看该作者
    未定位到元素,可以在定位元素后加入print 打印一下,看哪个定位出问题了。。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    3#
     楼主| 发表于 2017-7-5 11:28:15 | 只看该作者
    Miss_love 发表于 2017-7-4 15:26
    未定位到元素,可以在定位元素后加入print 打印一下,看哪个定位出问题了。。

    不是定位的问题 因为用户名密码不对的时候 就直接结束app啦 好像是if有问题 但是不知道问题在哪
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    无聊
    2020-12-8 11:20
  • 签到天数: 605 天

    连续签到: 1 天

    [LV.9]测试副司令

    4#
    发表于 2017-7-12 15:46:31 | 只看该作者
    你输入了错误的的信息,这个不是代码错误,测试代码完成了输入,不管对错,它都会执行下一步,然后就去会找元素,然后找一个不存在的元素就报错了。。。。
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-9-21 00:04 , Processed in 0.061910 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表