51Testing软件测试论坛

标题: 有selenium IDE录制的脚本导入到 [打印本页]

作者: 15889369825    时间: 2016-10-11 14:19
标题: 有selenium IDE录制的脚本导入到
selenium IDE录制的脚本导入到python IDLE中 运行报错
C:\Users\admin\Desktop\2.png
C:\Users\admin\Desktop\2.png
作者: 15889369825    时间: 2016-10-11 14:25
小白级别,不知道怎么错了,求解
作者: 若尘_51    时间: 2016-10-11 15:29
这个报错通常是:行缩进问题(空格或Tab的使用,看看光标停留在哪里),  或者就是缺少括号
作者: 15889369825    时间: 2016-10-11 16:34
若尘_51 发表于 2016-10-11 15:29
这个报错通常是:行缩进问题(空格或Tab的使用,看看光标停留在哪里),  或者就是缺少括号

光标就停留在def那里,行缩进是缩进四个字符么
作者: 若尘_51    时间: 2016-10-11 17:05
15889369825 发表于 2016-10-11 16:34
光标就停留在def那里,行缩进是缩进四个字符么

你的脚本的def函数那里是不需要缩进的:

brower=xxx
def setUp(self):
    xxx
    xxx
作者: 15889369825    时间: 2016-10-11 17:17
若尘_51 发表于 2016-10-11 17:05
你的脚本的def函数那里是不需要缩进的:

brower=xxx

不缩进也报同样的错误,这个会不会是我python环境没有装好
作者: 掉渣饼    时间: 2016-10-11 17:21
感觉是你的文件名称有问题,不能以中文名称命名
作者: 若尘_51    时间: 2016-10-11 17:24
15889369825 发表于 2016-10-11 17:17
不缩进也报同样的错误,这个会不会是我python环境没有装好

你把脚本附上来,我调调看
作者: 15889369825    时间: 2016-10-11 17:26
掉渣饼 发表于 2016-10-11 17:21
感觉是你的文件名称有问题,不能以中文名称命名

改了名称也一样,弄得没脾气了
作者: 15889369825    时间: 2016-10-11 17:29
若尘_51 发表于 2016-10-11 17:24
你把脚本附上来,我调调看

# -*- 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 3(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_3(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_id("email").clear()
        driver.find_element_by_id("email").send_keys("15889369825@163.com")
        driver.find_element_by_id("password").clear()
        driver.find_element_by_id("password").send_keys("123456")
        driver.find_element_by_id("check").clear()
        driver.find_element_by_id("check").send_keys("5223")
   
    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()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
   
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

作者: 若尘_51    时间: 2016-10-11 17:31
15889369825 发表于 2016-10-11 17:29
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import  ...

这个脚本你只需要将
class 3 改成 class test 就可以运行
作者: 若尘_51    时间: 2016-10-11 17:32
15889369825 发表于 2016-10-11 17:29
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import  ...

你附图的那个脚本为啥少了class
还有函数名不能包含中文的
作者: 15889369825    时间: 2016-10-11 17:40
若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的

刚运行了下,打开网页是无效的网址并没有打开我代码中的地址
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\3.py", line 12, in setUp
    self.driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
    "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.


----------------------------------------------------------------------
Ran 1 test in 15.122s

FAILED (errors=1)
作者: 15889369825    时间: 2016-10-11 17:42
若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的

附图的自己调试时被删除了,
运行了出现这个报错
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\3.py", line 12, in setUp
    self.driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
    "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.


----------------------------------------------------------------------
Ran 1 test in 21.165s

FAILED (errors=1)
作者: 15889369825    时间: 2016-10-11 17:43
若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的

大神就是厉害!不过我这边打不开脚本中的地址
作者: 15889369825    时间: 2016-10-11 17:44
若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的

厉害了大神,可我这边又出现新问题,打不开脚本中的地址
作者: 15889369825    时间: 2016-10-11 17:47
若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的

不好意思了!应该是调试修改时把class删除了
作者: 15889369825    时间: 2016-10-11 17:50
若尘_51 发表于 2016-10-11 17:32
你附图的那个脚本为啥少了class
还有函数名不能包含中文的

估计是调试的时候被我删除了,不好意思了
现在运行时打不开我脚本中的地址,后面报
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\3.py", line 12, in setUp
    self.driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
    "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.


----------------------------------------------------------------------
Ran 1 test in 21.165s

FAILED (errors=1)
作者: 15889369825    时间: 2016-10-11 17:58
应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\3.py", line 12, in setUp
    self.driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
    "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.


----------------------------------------------------------------------
Ran 1 test in 21.165s

FAILED (errors=1)
这是什么原因

作者: 15889369825    时间: 2016-10-11 17:58
应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\3.py", line 12, in setUp
    self.driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
    "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.


----------------------------------------------------------------------
Ran 1 test in 21.165s

FAILED (errors=1)
这是什么原因

作者: 15889369825    时间: 2016-10-11 17:59
应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\3.py", line 12, in setUp
    self.driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
    "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.


----------------------------------------------------------------------
Ran 1 test in 21.165s

FAILED (errors=1)
这是什么原因

作者: 15889369825    时间: 2016-10-11 18:01
为毛在这里回复帖子要审核
作者: 15889369825    时间: 2016-10-11 18:06
若尘_51 发表于 2016-10-11 17:31
这个脚本你只需要将
class 3 改成 class test 就可以运行

应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\3.py", line 12, in setUp
    self.driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
    "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.


----------------------------------------------------------------------
Ran 1 test in 21.165s

FAILED (errors=1)
这是什么原因
作者: 15889369825    时间: 2016-10-11 18:07
若尘_51 发表于 2016-10-11 17:31
这个脚本你只需要将
class 3 改成 class test 就可以运行

应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\3.py", line 12, in setUp
    self.driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
    "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.


----------------------------------------------------------------------
Ran 1 test in 21.165s

FAILED (errors=1)
这是什么原因
作者: 15889369825    时间: 2016-10-11 18:07
应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
E
======================================================================
ERROR: test_3 (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\3.py", line 12, in setUp
    self.driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 99, in _wait_until_connectable
    "The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.


----------------------------------------------------------------------
Ran 1 test in 21.165s

FAILED (errors=1)
这是什么原因
作者: 若尘_51    时间: 2016-10-12 08:30
15889369825 发表于 2016-10-11 17:58
应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
E
=============== ...

通常出现这个错误是因为你的火狐没有安装在默认安装路径:
C盘的"C:\Program Files (x86)\Mozilla Firefox\firefox.exe  这个路径
作者: 晨曦丶寒    时间: 2016-10-12 10:37
本帖最后由 晨曦丶寒 于 2016-10-12 10:41 编辑
15889369825 发表于 2016-10-11 17:58
应该是我调试的时候误删了,不好意思了,现在运行脚本打不开我脚本中的链接地址还提示
E
=============== ...

def test_3(self):
        driver = self.driver
        driver.get(self.base_url + "/")
        driver.find_element_by_id("email").clear()
        driver.find_element_by_id("email").send_keys("15889369825@163.com")
        driver.find_element_by_id("password").clear()
        driver.find_element_by_id("password").send_keys("123456")
        driver.find_element_by_id("check").clear()
        driver.find_element_by_id("check").send_keys("5223")
这段代码 driver.get(self.base_url + "/"),去掉括号里面的+ "/"
   
作者: 15889369825    时间: 2016-10-12 11:07
晨曦丶寒 发表于 2016-10-12 10:37
def test_3(self):
        driver = self.driver
        driver.get(self.base_url + "/")

谢谢!已经弄好了,selenium2.53兼容火狐浏览器问题  
作者: 15889369825    时间: 2016-10-12 15:37
若尘_51 发表于 2016-10-12 08:30
通常出现这个错误是因为你的火狐没有安装在默认安装路径:
C盘的"C:\Program Files (x86)\Mozilla Firef ...

重装了狐火,脚本能跑完,但跑完后pyhton shell还是会这样提示,
作者: 若尘_51    时间: 2016-10-12 15:49
15889369825 发表于 2016-10-12 15:37
重装了狐火,脚本能跑完,但跑完后pyhton shell还是会这样提示,

你的火狐和selenium的版本是多少?
另外火狐安装的路径?
错误提示,以及脚本都附上吧。我在我的机器上跑跑~~
作者: 15889369825    时间: 2016-10-12 16:18
若尘_51 发表于 2016-10-12 15:49
你的火狐和selenium的版本是多少?
另外火狐安装的路径?
错误提示,以及脚本都附上吧。我在我的机器上 ...

pip (8.1.2)
selenium (2.53.6)
setuptools (0.6rc11)  
火狐:45.4.0  路径:C:\Program Files\Mozilla Firefox
脚本:# -*- 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 + "/")
        driver.find_element_by_id("email").clear()
        driver.find_element_by_id("email").send_keys("15889369825@163.com")
        driver.find_element_by_id("password").clear()
        driver.find_element_by_id("password").send_keys("qwe123")
        driver.find_element_by_id("check").clear()
        driver.find_element_by_id("check").send_keys("7909")
        driver.find_element_by_id("submit").click()
        driver.find_element_by_id("userEmail").click()
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        driver.find_element_by_id("old_password").clear()
        driver.find_element_by_id("old_password").send_keys("12")
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("12")
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("12")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        driver.find_element_by_id("old_password").clear()
        driver.find_element_by_id("old_password").send_keys("!@#123456")
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("123456")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("123456")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        driver.find_element_by_id("old_password").click()
        driver.find_element_by_id("old_password").clear()
        driver.find_element_by_id("old_password").send_keys("qq123456")
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("!@#123456")
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("!@#123456")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        driver.find_element_by_id("userEmail").click()
        driver.find_element_by_id("old_password").clear()
        driver.find_element_by_id("old_password").send_keys("!@#123456")
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("!@#123456")
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("!@#123456")
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("qwe")
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("qwe")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("qwe123")
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("qwe123")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
   
    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()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
   
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()


错误提示:E
======================================================================
ERROR: test_ (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\xiugai.py", line 53, in test_
    driver.find_element_by_id("userEmail").click()
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 72, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 461, in _execute
    return self._parent.execute(command, params)
  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)
WebDriverException: Message: Element is not clickable at point (1103.9833374023438, 24.5). Other element would receive the click: <div style="display: block;" class="modal fade modal-resetPass in" id="resetPassModal" tabindex="-1" role="dialog" aria-labelledby="resetPassModalLabel" aria-hidden="true"></div>


----------------------------------------------------------------------
Ran 1 test in 27.051s

FAILED (errors=1)
>>>

作者: 若尘_51    时间: 2016-10-12 16:32
注:
(1)你的脚本可读性太差了,建议学习下别人的脚本。
(2)学习阅读脚本报错的信息:
Traceback (most recent call last):
  File "C:\Users\admin\Desktop\xiugai.py", line 53, in test_
    driver.find_element_by_id("userEmail").click()

  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 72, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 461, in _execute
    return self._parent.execute(command, params)
  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)
WebDriverException: Message: Element is not clickable at point (1103.9833374023438, 24.5). Other element would receive the click: <div style="display: block;" class="modal fade modal-resetPass in" id="resetPassModal" tabindex="-1" role="dialog" aria-labelledby="resetPassModalLabel" aria-hidden="true"></div>


脚本:# -*- 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 + "/")
        driver.find_element_by_id("email").clear()
        driver.find_element_by_id("email").send_keys("15889369825@163.com")
        driver.find_element_by_id("password").clear()
        driver.find_element_by_id("password").send_keys("qwe123")
        driver.find_element_by_id("check").clear()
        driver.find_element_by_id("check").send_keys("7909")
        driver.find_element_by_id("submit").click()
        driver.find_element_by_id("userEmail").click()
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        driver.find_element_by_id("old_password").clear()
        driver.find_element_by_id("old_password").send_keys("12")
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("12")
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("12")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        driver.find_element_by_id("old_password").clear()
        driver.find_element_by_id("old_password").send_keys("!@#123456")
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("123456")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("123456")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        driver.find_element_by_id("old_password").click()
        driver.find_element_by_id("old_password").clear()
        driver.find_element_by_id("old_password").send_keys("qq123456")
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("!@#123456")
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("!@#123456")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        #这句是多余的:driver.find_element_by_id("userEmail").click()
        #你本来就已经点进这个界面,所以无法再定位到这个元素上,因此这句报错

        driver.find_element_by_id("old_password").clear()
        driver.find_element_by_id("old_password").send_keys("!@#123456")
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("!@#123456")
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("!@#123456")
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("qwe")
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("qwe")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
        driver.find_element_by_id("new_password").clear()
        driver.find_element_by_id("new_password").send_keys("qwe123")
        driver.find_element_by_id("repeat").clear()
        driver.find_element_by_id("repeat").send_keys("qwe123")
        driver.find_element_by_css_selector("div.form-group > button.btn.btn-blue").click()
   
    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()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
   
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()
作者: 15889369825    时间: 2016-10-12 16:38
嗯!谢谢,刚开始学习这个,还有很多不懂,能推荐些资料看么




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2