Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3404038
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:20:01+00:00 2026-05-18T05:20:01+00:00

I know that /Interface \d/ occurs three times on the page. But I don’t

  • 0

I know that /Interface \d/ occurs three times on the page. But I don’t know how to test for this with Capybara in Cucumber. Here was my first attempt:

Then /^(?:|I )should see \/([^\/]*)\/ (\d+)(?:x|X| times?)?$/ do |regexp, count|
  regexp = Regexp.new(regexp)
  count = count.to_i
  if page.respond_to? :should
    page.should have_xpath('//*', { :text => regexp, :count => count })
  else
    assert page.has_xpath?('//*', { :text => regexp, :count => count })
  end
end

However, this returns false for my Then I should see /Interface \d+/ 3 times.

I figured out that this is because has_xpath uses all. Putting this in my test:

puts all(:xpath, '//*', { :text => regexp}).map {|e| pp e}

results in

#<Capybara::Element tag="html" path="/html">
#<Capybara::Element tag="body" path="/html/body">
#<Capybara::Element tag="div" path="/html/body/div">
#<Capybara::Element tag="div" path="/html/body/div/div[2]">
#<Capybara::Element tag="table" path="/html/body/div/div[2]/table">
#<Capybara::Element tag="tbody" path="/html/body/div/div[2]/table/tbody">
#<Capybara::Element tag="tr" path="/html/body/div/div[2]/table/tbody/tr[1]">
#<Capybara::Element tag="td" path="/html/body/div/div[2]/table/tbody/tr[1]/td[3]">
#<Capybara::Element tag="tr" path="/html/body/div/div[2]/table/tbody/tr[2]">
#<Capybara::Element tag="td" path="/html/body/div/div[2]/table/tbody/tr[2]/td[3]">
#<Capybara::Element tag="tr" path="/html/body/div/div[2]/table/tbody/tr[3]">
#<Capybara::Element tag="td" path="/html/body/div/div[2]/table/tbody/tr[3]/td[3]">

So I am getting a count of every step along the way to the elements that contain my text. :-\

I thought maybe has_content would save me, but it doesn’t accept a count.

Help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:20:02+00:00Added an answer on May 18, 2026 at 5:20 am

    Something like this should work:

    Then /^(?:|I )should see \/([^\/]*)\/ (\d+)(?:x|X| times?)?$/ do |regexp, count|
      regexp = Regexp.new(regexp)
      count = count.to_i
      page.find(:xpath, '//body').text.split(regexp).length.should == count+1
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that you can't have a constructor in an interface, but here is
I am still not so familiar with interfaces in Java. I know that interface
I know that an interface does not have a body, just a method definition.
As you know, OAuth can support RSA-SHA1 Signature. I have an OAuthSignature interface that
I know nothing about Xcode, except it's a Developer interface from Apple that actually
I know that it's a subject that can raise a lot of debate, but
I know that I should put all the html elements in body tag, but
I know that one of the differences between classes and structs is that struct
I know that exceptions have a performance penalty, and that it's generally more efficient
We know that behind the scenes, the ASP.NET MVC framework will use reflection to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.