python+selenium的alert

alert\confirm\prompt彈出框操作主要方法有:
text:獲取文本值
accept() :點擊"確認"
dismiss() :點擊"取消"或者叉掉對話框
send_keys() :輸入文本值 --僅限於prompt,在alert和confirm上沒有輸入框
如以下的html的語言

  Alert python測試: from selenium import webdriver a=webdriver.Chrome() a.get('http://www.baidu.com') a.get_screenshot_as_file('C:\\Users\\Public\\Pictures\\Sample Pictures\\1111.png') a.get('http://news.baidu.com') a.get('file:///E:/web%E5%89%8D%E7%AB%AF%E8%A7%86%E9%A2%91/05.javascript%E9%AB%98%E7%BA%A7(%E5%85%B1110%E5%A4%9A%E9%9B%86)/%E8%B5%84%E6%96%99/03-JavaScript-%E9%AB%98%E7%BA%A7-%E7%AC%AC5%E5%A4%A9/04%E6%BA%90%E4%BB%A3%E7%A0%81/256rgb.html') a.find_element_by_id('alert').click() webdriver.execute_script('window.alert("test");') webdriver.switch_to_alert().accept()

a.quit()
運行結果如下圖:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章