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 7163961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:59:24+00:00 2026-05-28T13:59:24+00:00

I’m writing a test suite with Capybara, and I need to test the length

  • 0

I’m writing a test suite with Capybara, and I need to test the length of a textbox in Ruby. It has a limit of 255 characters. Once the limit is reached you can’t type anymore. So what I’m looking for is to count the number of characters that has been typed into the text box to ensure it doesnt exceed 255 characters. This is being done in Ruby (I’ve only started learning code so all new to me, any help would be great).

The :xpath /html/body/div[4]/div[2]/div[7]

I’ve researched a lot and all the code I can find is how to create a text box and to put a limit of the characters but I’m looking for code that can test that it works.

Stuff I’ve found like a.count or content.count but I cant get it to work.

Any help would be appreciated. Thanks in advance.

  • 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-28T13:59:26+00:00Added an answer on May 28, 2026 at 1:59 pm

    Ruby code can help you generate the textbox you need, but it won’t track how the user is using it – at least not directly. That’s the job of the browser and the javascript you write to catch browser events. And yes, you can catch each key press and send the result back to your server using AJAX so that you can process it in ruby, but why would you want to do any of this?

    What you probably want is a ruby helper that can generate some html to tell the browser to limit the textbox input to a certain count.

    Something like this, perhaps:

    <%= text_box 'some_model', 'some_attribute' , :maxlength=>"255" %>
    

    For text_area something like this:

    <%= text_area 'some_model', 'some_attribute', 
      :onchange => "if (this.value.length > 255){ this.value = this.value.substr(0,255); }" %>
    

    Or better yet, put that javascript in a helper .js file and add it using jQuery or the like.

    UPDATED

    To test the content length using RSpec/capybara with the xpath selector you provided:

    find(:xpath, "/html/body/div[4]/div[2]/div[7]/textbox").value.length.should_be 255
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.