# -*- coding: utf-8 -*-
from selenium import webdriver
fromselenium.webdriver.common.byimportBy
fromselenium.webdriver.common.keysimportKeys
fromselenium.webdriver.support.uiimportSelect
fromselenium.common.exceptionsimportNoSuchElementException
fromselenium.common.exceptionsimportNoAlertPresentException
importunittest, time, re
classTestOne(unittest.TestCase):
defsetUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url =\”http://10.190.1.38/\”
self.verificationErrors = []
self.accept_next_alert =True
deftest_one(self):
driver =self.driver
driver.get(self.base_url +\”/ums/coframe/auth/login/login.jsp\”)
driver.find_element_by_id(\”userId$text\”).clear()
driver.find_element_by_id(\”userId$text\”).send_keys(\”sysadmin\”)
driver.find_element_by_id(\”password$text\”).clear()
driver.find_element_by_id(\”password$text\”).send_keys(\”000000\”)
driver.find_element_by_css_selector(\”input.log\”).click()
driver.find_element_by_xpath(\”(//a[@onclick=\’return false;\’])[4]\”).click()
driver.find_element_by_xpath(\”(//a[@onclick=\’return false;\’])[5]\”).click()
driver.find_element_by_xpath(\”//td[@id=\’53$cell$1\’]/div/div/span[4]\”).click()
# ERROR: Caught exception [ERROR: Unsupported command [selectFrame | main | ]]
driver.find_element_by_xpath(\”//a[3]/span\”).click()
driver.find_element_by_css_selector(\”#mini-32 > span.mini-button-text.\”).click()
defis_element_present(self, how, what):
try:self.driver.find_element(by=how,value=what)
exceptNoSuchElementExceptionase:returnFalse
returnTrue
defis_alert_present(self):
try:self.driver.switch_to_alert()
exceptNoAlertPresentExceptionase:returnFalse
returnTrue
defclose_alert_and_get_its_text(self):
try:
alert =self.driver.switch_to_alert()
alert_text = alert.text
ifself.accept_next_alert:
alert.accept()
else:
alert.dismiss()
returnalert_text
finally:self.accept_next_alert =True
deftearDown(self):
self.driver.quit()
self.assertEqual([],self.verificationErrors)
if__name__ ==\”__main__\”:
unittest.main()
自动化测试群:369353583