十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Selenese---Selenium提供的可以进行全面的Web应用测试的命令的总称。可以通过http://release.seleniumhq.org/selenium-core/1.0.1/reference.html 查询。
成都创新互联公司专业为企业提供桑珠孜网站建设、桑珠孜做网站、桑珠孜网站设计、桑珠孜网站制作等企业网站建设、网页设计与制作、桑珠孜企业网站模板建站服务,十年桑珠孜做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。该命令主要有三种子类型,Actions、Accessors和 Assertions:
附上测试gmail登录的脚本。应该可以精简许多,明天在研究了。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
class Test(unittest.TestCase):
def setUp(self):
self.driver= webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url= "https://accounts.google.com"
self.verificationErrors= []
self.accept_next_alert= True
def test_(self):
driver= self.driver
driver.get(self.base_url+ "/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2")
# ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.] # ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.] driver.find_element_by_id("Email").send_keys("******")
driver.find_element_by_id("Passwd").send_keys("******")
driver.find_element_by_id("signIn").click()
# Warning: assertTextPresent may require manual changes #self.assertRegexpMatches(driver.find_element_by_css_selector("BODY").text, r"^[sS]*Gmail[sS]*$")
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert= self.driver.switch_to_alert()
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()