TA的每日心情 | 慵懒 2017-11-7 16:44 |
---|
签到天数: 290 天 连续签到: 1 天 [LV.8]测试军长
|
注:
(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() |
|