html tool

2014年11月4日星期二

js for selenium 的例子python

python 源码
------------------------------------------------------------------------
    def test_alert(self):
        driver = self.driver
        driver.get(self.base_url + "file:///1-alert.html")
        driver.find_element_by_css_selector("button[value=\"alert\"]").click()
        #self.assertEqual(u"hi!", self.close_alert_and_get_its_text())
# 获得alert的焦点并处理
alert = driver.switch_to_alert()
print alert.text # alert 提示内容
alert.accept()

#getprompt
driver.find_element_by_css_selector("body > button").click()
alert = driver.switch_to_alert()
alert.send_keys("im here")
print alert.text #提示内容
alert.accept()
#print alert.text

#confirm
driver.find_element_by_xpath("//button[@onclick='myFunction_confirm()']").click()
alert =  driver.switch_to_alert()
print alert.text
alert.accept()

driver.find_element_by_xpath("//button[@onclick='myFunction_confirm()']").click()
alert =  driver.switch_to_alert()
print alert.text
alert.dismiss()
print driver.find_element_by_xpath("//p[@id='demo2']").text

------------------------------------------------------------------------
js 源码
------------------------------------------------------------------------



 


 Click the button to demonstrate the prompt box.







Click the button to display a confirm box.







----------------------参考-----------------------------
js:
http://www.w3schools.com/jsref/met_win_prompt.asp
http://www.w3schools.com/jsref/met_win_confirm.asp
python selenium API
http://selenium-python.readthedocs.org/en/latest/api.html

没有评论:

发表评论