在selenium中发送警报中的文本

时间:2015-11-23 07:17:08

标签: javascript selenium

如何处理包含用户名和密码等文本字段的JavaScript警报?如何在这些字段中输入值?

enter image description here

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

driver.switch_to.alert.authenticate('cheese', 'secretGouda')

您可以在控制台或link上查看该文档。

>>> from selenium.webdriver.common.alert import Alert
>>> help(Alert.authenticate)
Help on method authenticate in module selenium.webdriver.common.alert:

authenticate(self, username, password) unbound selenium.webdriver.common.alert.Alert method
    Send the username / password to an Authenticated dialog (like with Basic HTTP Auth).
    Implicitly 'clicks ok'

    Usage::
    driver.switch_to.alert.authenticate('cheese', 'secretGouda')

    :Args:
     -username: string to be set in the username section of the dialog
     -password: string to be set in the password section of the dialog