51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2265|回复: 7
打印 上一主题 下一主题

python

[复制链接]
  • TA的每日心情
    开心
    2017-2-23 09:15
  • 签到天数: 13 天

    连续签到: 1 天

    [LV.3]测试连长

    跳转到指定楼层
    1#
    发表于 2016-12-1 14:52:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    # -*- 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
    from selenium.common.exceptions import NoAlertPresentException
    import unittest, time, re

    class test (unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Firefox()
            self.driver.implicitly_wait(30)
            self.base_url = "http://test.robotscloud.com/"
            self.verificationErrors = []
            self.accept_next_alert = True

        def test_(self):
            driver = self.driver
            driver.get(self.base_url + "/adminsystem/platform_user")
            driver.find_element_by_id("email").clear()
            driver.find_element_by_id("email").send_keys("2@163.com")
            driver.find_element_by_id("password").clear()
            driver.find_element_by_id("password").send_keys("123456")
            driver.find_element_by_id("submit").click()
            driver.find_element_by_link_text(u"系统管理").click()
            driver.find_element_by_link_text(u"平台子用户设置").click()
            driver.find_element_by_link_text(u"新增").click()
            driver.find_element_by_css_selector("div.form-group.button-group > button.btn.btn-blue").click()
            driver.find_element_by_name("email").clear()
            driver.find_element_by_name("email").send_keys("2@163.com")
            driver.find_element_by_css_selector("div.form-group.button-group > button.btn.btn-blue").click()
            driver.find_element_by_name("email").click()
            driver.find_element_by_name("email").clear()
            driver.find_element_by_name("email").send_keys("@163.com")
            driver.find_element_by_css_selector("div.form-group.button-group > button.btn.btn-blue").click()
            driver.find_element_by_name("email").click()
            driver.find_element_by_name("email").clear()

        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()

    运行后报  driver.find_element_by_link_text(u"平台子用户设置").click()  这个错误     但这个我在wind10  python2.7上面运行正常    在wind7  python2.7.12上面运行就报错,怎么解决

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

    使用道具 举报

  • TA的每日心情
    慵懒
    2017-11-7 16:44
  • 签到天数: 290 天

    连续签到: 1 天

    [LV.8]测试军长

    2#
    发表于 2016-12-1 16:51:46 | 只看该作者
    报什么错误附上来看看咯~~
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2017-2-23 09:15
  • 签到天数: 13 天

    连续签到: 1 天

    [LV.3]测试连长

    3#
     楼主| 发表于 2016-12-1 17:03:50 | 只看该作者
    若尘_51 发表于 2016-12-1 16:51
    报什么错误附上来看看咯~~


    ======================================================================
    ERROR: test_ (__main__.test)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "F:\萝卜头自动化脚本\管理平台\xitongguanl.py", line 26, in test_
        driver.find_element_by_link_text(u"绯荤粺绠$悊").click()
      File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 317, in find_element_by_link_text
        return self.find_element(by=By.LINK_TEXT, value=link_text)
      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\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
        raise exception_class(message, screen, stacktrace)
    NoSuchElementException: Message: Unable to locate element: \u7cfb\u7edf\u7ba1\u7406


    ----------------------------------------------------------------------
    Ran 1 test in 38.389s

    FAILED (errors=1)

    调用谷歌跑程序这里没有错,狐火就会报错
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2017-11-7 16:44
  • 签到天数: 290 天

    连续签到: 1 天

    [LV.8]测试军长

    4#
    发表于 2016-12-1 17:08:57 | 只看该作者
    15889369825 发表于 2016-12-1 17:03
    ======================================================================
    ERROR: test_ (__main__.t ...

    加个等待时间或者换种定位方法试试~~
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2017-2-23 09:15
  • 签到天数: 13 天

    连续签到: 1 天

    [LV.3]测试连长

    5#
     楼主| 发表于 2016-12-1 17:10:28 | 只看该作者
    若尘_51 发表于 2016-12-1 17:08
    加个等待时间或者换种定位方法试试~~

    加了时间等待,但没效果,定位方式也换了,还是不行,不知道是不是定位错误
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2017-11-7 16:44
  • 签到天数: 290 天

    连续签到: 1 天

    [LV.8]测试军长

    6#
    发表于 2016-12-1 17:19:44 | 只看该作者
    15889369825 发表于 2016-12-1 17:10
    加了时间等待,但没效果,定位方式也换了,还是不行,不知道是不是定位错误

    这就怪了,没辙了,没遇过这种情形。
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2017-2-23 09:15
  • 签到天数: 13 天

    连续签到: 1 天

    [LV.3]测试连长

    7#
     楼主| 发表于 2016-12-1 17:27:50 | 只看该作者
    若尘_51 发表于 2016-12-1 17:19
    这就怪了,没辙了,没遇过这种情形。

    换成调用谷歌就ok了,是不是脚本的可读性太差
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2017-11-7 16:44
  • 签到天数: 290 天

    连续签到: 1 天

    [LV.8]测试军长

    8#
    发表于 2016-12-2 10:04:18 | 只看该作者
    15889369825 发表于 2016-12-1 17:27
    换成调用谷歌就ok了,是不是脚本的可读性太差

    没遇到过这种情况,也不好判断是什么原因:
    在谷歌里执行没有问题,起码说明脚本没有问题。
    有可能是:
    (1)编码的问题,试试不用使用中文的定位方式
    (2)可能是谷歌和火狐处理机制有点不一样,会不会是火狐是不是有阻挡层,或这个元素是隐藏的,
    所以定位不出来
    其他就想不到。具体还是你仔细研究下那个测试的页面吧
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

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

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

    GMT+8, 2024-9-20 22:45 , Processed in 0.067372 second(s), 22 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

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