The alert, confirm, and prompt generated by JS are processed in Webdriver, and the Switch_to_alert () method is used to locate the alert/confirm/prompt. Then use Text/accept/dismiss/send_keys to operate
①text: Returns the text information in the Alert/confirm/prompt
②accept: Click the Confirm button
③dismiss: Click the Cancel button
④send_keys: Input value, this alert/confirm/prompt no dialog box can not be used, or will be error
Eg: the settings page of Baidu, click "Save Settings" to play the prompt box after Setup is complete.
=======================================================
#!/usr/bin/python
#-*-Coding:utf-8-*-
__author__ = ' Zuoanvip '
From selenium import Webdriver
Import time
Driver = Webdriver. Firefox ()
Driver.get (' http://www.baidu.com ')
#打开搜索设置
Driver.find_element_by_name (' tj_setting '). Click ()
driver.find_element_by_id (' Sl_1 '). Click ()
#点击保存设置
button = Driver.find_element_by_xpath ('//div[@id = ' Gxszbutton ']/input ')
Button.Click ()
#获取网页上的警告信息
Alert = Driver.switch_to_alert ()
#接收警告信息
Alert.accept ()
#打印警告中的文字信息
Alert.text ()
#点击取消按钮
Alert.dismiss ()
#输入值
Alert.send_keys (' Test ')
Selenium python (11) Alert/confirm/prompt Processing (popup box in JS)