You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Robot Framework弹窗多提示处理异常:仅验证单个提示求助

弹窗多提示信息的处理方案

问题说明

弹窗包含两条必填项提示:

    • Country Description is required.(国家描述为必填项)
    • Currency is required.(货币为必填项)
      但目前仅能验证其中一条,尝试以下两种代码方案均未生效:

代码方案1:

Handle Alert    * Country Description is required.* Currency is required.  Leave  
sleep  2
Handle Alert    ACCEPT

代码方案2:

Alert Should Be Present        * Country Description is required. LEAVE
Alert Should Be Present        * Currency is required.        LEAVE
Handle Alert    ACCEPT

解决方法

  1. 匹配完整弹窗文本(含换行)
    弹窗内的两条提示大概率是分行显示的,需用\n匹配换行符来验证完整文本:
Alert Should Be Present    * Country Description is required.\n* Currency is required.
Handle Alert    ACCEPT
  1. 先获取弹窗文本再分别验证
    先确认弹窗存在,再提取文本内容分别检查两条提示:
Alert Should Be Present
${alert_text}=    Get Alert Text
Should Contain    ${alert_text}    Country Description is required.
Should Contain    ${alert_text}    Currency is required.
Handle Alert    ACCEPT
  1. 排查是否为自定义模态框
    如果这不是原生JS弹窗,而是网页自定义的模态框,Handle Alert这类关键字不生效,需通过元素定位操作:
Wait Until Element Is Visible    //div[contains(text(),'Country Description is required.')]
Wait Until Element Is Visible    //div[contains(text(),'Currency is required.')]
Click Button    //button[text()='ACCEPT']

内容的提问来源于stack exchange,提问作者reyansh yadav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 01:57:18