【问题标题】:Verify webelement using "@current_page" in watir在 watir 中使用“@current_page”验证 webelement
【发布时间】:2026-02-01 02:55:02
【问题描述】:

Step1 和 Step2 带我回到“LandingPage”。我想使用@current_page 验证元素。 这是在“LandingPage.rb”中定义的元素。

我试过这个,但没有运气。缺少什么?

Step1
Step2

1. fail if not @current_page.(on(LandingPage.cart_box.present?))
2. fail if not @current_page.(on(LandingPage.cart_box)).present?
3. fail if not @current_page.(on(LandingPage.cart_box_element)).present?

【问题讨论】:

    标签: ruby watir verify current-page


    【解决方案1】:

    假设@current_page 设置在Step1Step2 中,它将是LandingPage 的一个实例。你不应该调用on 方法。

    根据您的目标,您可以执行以下任一操作:

    @current_page.cart_box?
    

    或者

    @current_page.cart_box_element.visible?
    

    请注意,如果您希望检查使测试失败,则需要在测试框架的断言库中使用结果。

    【讨论】: