TA的每日心情 | 开心 2017-2-23 09:15 |
---|
签到天数: 13 天 连续签到: 1 天 [LV.3]测试连长
|
# -*- 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 Qi(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_qi(self):
driver = self.driver
driver.get(self.base_url + "/admindocmanage/admin_doc_center")
driver.find_element_by_id("email").send_keys("2@163.com")
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_id("search-input").click()
driver.find_element_by_id("search-input").clear()
driver.find_element_by_id("search-input").send_keys(u"想")
driver.find_element_by_id("btn-search").click()
driver.find_element_by_id("search-input").clear()
driver.find_element_by_id("search-input").send_keys(u"狗")
driver.find_element_by_id("btn-search").click()
driver.find_element_by_id("search-input").clear()
driver.find_element_by_id("search-input").send_keys("l")
driver.find_element_by_id("btn-search").click()
driver.find_element_by_id("search-input").clear()
driver.find_element_by_id("search-input").send_keys(u"的")
driver.find_element_by_id("btn-search").click()
driver.find_element_by_id("addUser").click()
driver.find_element_by_css_selector("span.label").click()
driver.find_element_by_css_selector("li.last").click()
driver.find_element_by_xpath("//div[@id='modal-body-dialog']/form/div[2]/div/div[2]/span").click()
driver.find_element_by_xpath("//div[@id='modal-body-dialog']/form/div[2]/div/div[3]/div/ul/li[2]").click()
driver.find_element_by_id("chooseImg").click()
driver.find_element_by_xpath("//div[@id='modal-body-dialog']/form/div[5]/table/tbody/tr/td[3]/img").click()
driver.find_element_by_class_name("up_text").send_keys(u"F:/cylan-2.4.9.840-2016111818-(test.jfgou.com)-Inhouse)")
driver.find_element_by_xpath("//div[@id='modal-body-dialog']/form/div[7]/div/div[2]/span").click()
driver.find_element_by_xpath("//div[@id='modal-body-dialog']/form/div[7]/div/div[3]/div/ul/ul/li[2]").click()
driver.find_element_by_name("abstract").clear()
driver.find_element_by_name("abstract").send_keys(u"221谔谔")
driver.find_element_by_id("journal").clear()
driver.find_element_by_id("journal").send_keys(u"2呃3呃3呃呃")
# driver.find_element_by_css_selector("#sizzle1479805746127 > label.radio-label.form-label1").click()
driver.find_element_by_id("sendEmail").click()
driver.find_element_by_xpath("//div[@id='modal-body-dialog']/form/div[11]/div/div[2]/span").click()
driver.find_element_by_xpath("//div[@id='modal-body-dialog']/form/div[11]/div/div[3]/div/ul/li[5]").click()
driver.find_element_by_id("confirm").click()
# driver.find_element_by_id("search-input").click()
# driver.find_element_by_id("search-input").clear()
driver.find_element_by_id("search-input").send_keys("")
# driver.find_element_by_id("btn-search").click()
driver.find_element_by_class_name(u"编辑").click()
driver.find_element_by_name("abstract").clear()
driver.find_element_by_name("abstract").send_keys(u"221谔谔;/i/;")
driver.find_element_by_xpath("//div[@id='modal-body-dialog']/form/div[7]/div/div[2]/span").click()
driver.find_element_by_css_selector("ul.selectric-group > li.last").click()
driver.find_element_by_id("journal").clear()
driver.find_element_by_id("journal").send_keys(u"2呃3呃3呃呃i/i/i/i//i/;/;/")
driver.find_element_by_id("confirm").click()
driver.find_element_by_link_text(u"操作日志").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()
报这个错误
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\admin\Desktop\qi.py", line 62, in test_qi
driver.find_element_by_xpath(u"(//a[contains(text(),'缂栬緫')])[10]").click()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 293, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
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: {"method":"xpath","selector":"(//a[contains(text(),'\u7f16\u8f91')])[10]"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///c:/users/admin/appdata/local/temp/tmp8jg6hk/extensions/fxdriver@googlecode.com/components/driver-component.js:10770)
at fxdriver.Timer.prototype.setTimeout/<.notify (file:///c:/users/admin/appdata/local/temp/tmp8jg6hk/extensions/fxdriver@googlecode.com/components/driver-component.js:625)
----------------------------------------------------------------------
Ran 1 test in 52.406s
FAILED (errors=1)
>>>
=================== RESTART: C:\Users\admin\Desktop\qi.py ===================
E
======================================================================
ERROR: test_qi (__main__.Qi)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\admin\Desktop\qi.py", line 62, in test_qi
driver.find_element_by_class_name(u"缂栬緫").click()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 413, in find_element_by_class_name
return self.find_element(by=By.CLASS_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\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: Unable to locate element: {"method":"class name","selector":"\u7f16\u8f91"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///c:/users/admin/appdata/local/temp/tmpi6zugx/extensions/fxdriver@googlecode.com/components/driver-component.js:10770)
at fxdriver.Timer.prototype.setTimeout/<.notify (file:///c:/users/admin/appdata/local/temp/tmpi6zugx/extensions/fxdriver@googlecode.com/components/driver-component.js:625)
----------------------------------------------------------------------
Ran 1 test in 50.527s
FAILED (errors=1)
这个运行现象是没有上传到文件 但报的错误是编辑那个地方,但编辑那个地方换了 class_name link_text 几种定位都报错求解
|
|