弹出窗口

时间:2017-04-30 20:02:00

标签: javascript python html selenium

我正在尝试使用Python和Selenium选择确认框。我可以单击“转移”按钮,然后系统提示我“是否确定要将所选帐户项目和权限转移到备份备份(备份)?”然后有两个按钮
1.“取消”
2.“确定”

Click transfer button to transfer account

当我到达这个部分时,我无法让Selenium进入下一步,即单击“确定”按钮。

"OK" button to confirm account transfer

下面是HTML。

<div style="padding-top: 15px;">
<input id="submit_transfer" class="button" name="submit_transfer" onclick="return verifyTransfer('');" value="Transfer" type="submit"/>
<input id="do_transfer" name="do_transfer" value="0" type="hidden"/>
<input id="delete_user" name="delete_user" value="0" type="hidden"/>
<input id="cancel_transfer" class="button" name="cancel_transfer" value="Cancel" type="submit"/>
</div>

def transfer_account(drive):
    """

    :param drive: 
    :return: 
    """
    transfer_account_xpath = ".//*[@id='submit_transfer']"

    test = ".//*[@id='submit_transfer']"

    transfer_account_ = drive.find_element_by_xpath(transfer_account_xpath)
    transfer_account_.click()

    al = driver.switch_to.alert()
    print al.text

    time.sleep(3)

    # result = None
    # try:
    # except UnexpectedAlertPresentException:
    #     print 'error'

1 个答案:

答案 0 :(得分:0)

   try:
    WebDriverWait(drive, 3).until(EC.alert_is_present(),
                                    'Timed out waiting for PA creation ' +
                                    'confirmation popup to appear.')

    alert = drive.switch_to_alert()
    alert.accept()
    print "alert accepted"
except TimeoutException:
    print "no alert"