51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2866|回复: 5
打印 上一主题 下一主题

[求助] 参数化邮箱登陆

[复制链接]
  • TA的每日心情
    奋斗
    2020-12-11 22:39
  • 签到天数: 120 天

    连续签到: 1 天

    [LV.7]测试师长

    跳转到指定楼层
    1#
    发表于 2016-6-15 00:09:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    class Qq():
        #登陆
        def user_login(self,driver,username,password):
                driver.switch_to.frame("login_frame")
                driver.find_element_by_xpath("//input[@name='u']").clear()
                driver.find_element_by_xpath("//input[@name='u']").send_keys(username)
                driver.find_element_by_xpath("//input[@name='p']").clear()
                driver.find_element_by_xpath("//input[@name='p']").send_keys(password)
                driver.find_element_by_id("login_button").click()

    from selenium import webdriver
    from qqmail import Qq

    class LoginTest():
        def __init__(self):
            self.driver=webdriver.Ie()
            self.driver.implicitly_wait(10)
            self.driver.get("mail.qq.com")


            #admin用户登录
        def test_admin_login(self):
            username='admin'
            password='123'
            Qq().user_login(self.driver,username,password)
            self.driver.quit()

            #guest用户登录
        def test_guest_login(self):
            username='guest'
            password='321'
            Qq().user_login(self.driver,username,password)
            self.driver.quit()

    LoginTest().test_admin_login()
    LoginTest().test_guest_login()

    运行后报错:
    Traceback (most recent call last):
      File "F:/python/qq邮箱/参数化邮箱登陆.py", line 25, in <module>
        LoginTest().test_admin_login()
      File "F:/python/qq邮箱/参数化邮箱登陆.py", line 15, in test_admin_login
        Qq().user_login(self.driver,username,password)
      File "F:/python/qq邮箱\qqmail.py", line 5, in user_login
        driver.find_element_by_xpath("//input[@name='u']").clear()
      File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 88, in clear
        self._execute(Command.CLEAR_ELEMENT)
      File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", line 457, in _execute
        return self._parent.execute(command, params)
      File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute
        self.error_handler.check_response(response)
      File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.InvalidElementStateException: Message: Element must not be hidden, disabled or read-only


    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    2021-12-24 13:41
  • 签到天数: 314 天

    连续签到: 1 天

    [LV.8]测试军长

    2#
    发表于 2016-6-15 11:50:37 | 只看该作者
      driver.switch_to.frame("login_frame")这个你写错了  driver.switch_to_frame("login_frame")
      self.driver.get("mail.qq.com")改成self.driver.get("http://mail.qq.com")

    评分

    参与人数 1测试积点 +10 收起 理由
    lsekfe + 10 积极回复获得测试积点10

    查看全部评分

    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2020-12-11 22:39
  • 签到天数: 120 天

    连续签到: 1 天

    [LV.7]测试师长

    3#
     楼主| 发表于 2016-6-15 22:31:30 | 只看该作者
    掉渣饼 发表于 2016-6-15 11:50
    driver.switch_to.frame("login_frame")这个你写错了  driver.switch_to_frame("login_frame")
      self.d ...

    按照你说的方法,跑脚本还是报同样的错误,,麻烦再帮忙看一下,谢谢~
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2021-12-24 13:41
  • 签到天数: 314 天

    连续签到: 1 天

    [LV.8]测试军长

    4#
    发表于 2016-6-15 23:15:04 | 只看该作者
    kakaxi5221 发表于 2016-6-15 22:31
    按照你说的方法,跑脚本还是报同样的错误,,麻烦再帮忙看一下,谢谢~

    你建立两个文件qqmail.py,test.py这两个文件放到一个路径下
    qqmail.py:
    class Qq():
        #登陆
        def user_login(self,driver,username,password):
                driver.switch_to_frame("login_frame")
                driver.find_element_by_xpath("//input[@name='u']").clear()
                driver.find_element_by_xpath("//input[@name='u']").send_keys(username)
                driver.find_element_by_xpath("//input[@name='p']").clear()
                driver.find_element_by_xpath("//input[@name='p']").send_keys(password)
                driver.find_element_by_id("login_button").click()

    test.py:
    #coding=utf-8               
    from selenium import webdriver
    from qqmail import Qq

    class LoginTest():
        def __init__(self):
            self.driver=webdriver.Ie()
            self.driver.implicitly_wait(10)
            self.driver.get("http://mail.qq.com")


            #admin用户登录
        def test_admin_login(self):
            username='admin'
            password='123'
            Qq().user_login(self.driver,username,password)
            self.driver.quit()

            #guest用户登录
        def test_guest_login(self):
            username='guest'
            password='321'
            Qq().user_login(self.driver,username,password)
            self.driver.quit()


    LoginTest().test_admin_login()
    LoginTest().test_guest_login()       

    如果报错,把报错信息贴出来
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2021-12-24 13:41
  • 签到天数: 314 天

    连续签到: 1 天

    [LV.8]测试军长

    5#
    发表于 2016-6-15 23:50:00 | 只看该作者
    IE输入框在读取字符时比较慢,在定位输入框时等一会儿,输入的字符就出来了
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

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

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

    GMT+8, 2024-5-2 19:50 , Processed in 0.065505 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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