capybara: page.should have_no_content doesn't work correctly for display:none element

后端 未结 4 2080
你的背包
你的背包 2020-12-16 22:10

I would like to use page.should have_no_content to check if the page doesn\'t display the label to user, here what it is in HTML:

  • 4条回答
    •  北海茫月
      2020-12-16 22:23

      I found a solution using:

      Then /^"([^\"]+)" should not be visible$/ do |text|
        paths = [
          "//*[@class='hidden']/*[contains(.,'#{text}')]",
          "//*[@class='invisible']/*[contains(.,'#{text}')]",
          "//*[@style='display: none;']/*[contains(.,'#{text}')]"
        ]
        xpath = paths.join '|'
        page.should have_xpath(xpath)
      end
      

    提交回复
    热议问题