弹框
Alerts 警告框
获取文本并关闭警告
# Click the link to activate the alert
driver.find_element(:link_text, 'See an example alert').click
# Store the alert reference in a variable
alert = driver.switch_to.alert
# Store the alert text in a variable
alert_text = alert.text
# Press on OK button
alert.accept
Confirm 确认框
与警告类似,不同在于它还可以取消
# Click the link to activate the alert
driver.find_element(:link_text, 'See a sample confirm').click
# Store the alert reference in a variable
alert = driver.switch_to.alert
# Store the alert text in a variable
alert_text = alert.text
# Press on Cancel button
alert.dismiss
Prompt 提示框
提示框可能还需要输入文本
# Click the link to activate the alert
driver.find_element(:link_text, 'See a sample prompt').click
# Store the alert reference in a variable
alert = driver.switch_to.alert
# Type a message
alert.send_keys("selenium")
# Press on Ok button
alert.accept