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

如何用Capybara 3.6完成邮件验证与导航栏点击操作?

验证邮件中指定内容的多种Capybara方法
  • 直接匹配文本内容
    Capybara的have_content会自动忽略HTML标签,直接匹配文本内容,适合快速验证:

    # 根据邮件格式选择html_part(HTML邮件)或text_part(纯文本邮件)
    expect(mail.html_part.body).to have_content("Ok, first thing's first, please verify (at bottom).")
    
  • 通过CSS选择器验证
    利用你提供的CSS选择器定位<b>标签,精准验证目标文本:

    # 替换成实际的CSS选择器
    expect(mail.html_part).to have_css('你的CSS选择器', text: "Ok, first thing's first, please verify (at bottom).")
    
  • 通过XPath验证
    使用完整XPath定位元素,适合复杂结构的邮件内容验证:

    # 替换成你提供的完整XPath
    expect(mail.html_part).to have_xpath('你的完整XPath', text: "Ok, first thing's first, please verify (at bottom).")
    
  • 匹配原始HTML源码
    如果上述方法都不生效,可直接检查邮件的HTML源码:

    expect(mail.html_part.body).to include('<b>Ok, first thing\'s first, please verify (at bottom).</b>')
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 14:52:32