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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:14:21+00:00 2026-05-29T23:14:21+00:00

I am new to watir, and Need to know how to capture a value

  • 0

I am new to watir, and Need to know how to capture a value displayed on browser and pass the same as parameter to next step. here is how the html looks like.

Text –   xxxx yyyy zzzz aaaa

The text displayed is a card number. I need to capture the card number dipslayed and pass it as parameter to next step in my test

  • 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-29T23:14:23+00:00Added an answer on May 29, 2026 at 11:14 pm

    If this cardnumber is contained in an HTML element like a div/span/table cell, then use that to locate the bit of text you need.

    For example if your HTML was like this:

    <div class="CC_Number">1234 5678 9012 3456</div>
    

    Then you could use code like this:

    cardnumber = browser.div(:class => "CC_Number").text
    other_function(cardnumber)
    

    You can also use regular expressions or other string manipulation to separate the number from other text on the page.

    “Your credit card number is: 1234 5678 9012 3456.”

    cardnumber = browser.text              #get all browser text
         #"Your credit card number is: 1234 5678 9012 3456."
    cardnumber = cardnumber.split(":")     #split the text at every colon
         #[0] = "Your credit card number is"
         #[1] = "1234 5678 9012 3456."
    cardnumber[1].gsub(".", "")            #replace all instances of "." with ""
         #cardnumber = "1234 5678 9012 3456"
    

    for an example of a regular expression to find the card number, see @Dave McNulla’s answer below.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the .rb program: require 'watir' b = Watir::Browser.new the 2nd line will
Here is the Watir code I am using: require 'watir-classic' browser = Watir::IE.new browser.link(:class,
Now i have such watir code: require watir-webdriver browser = Watir::Browser.new :ff browser.driver.manage.timeouts.implicit_wait =
I'm brand new to ruby and Watir, here's my issue... I have a MySQL
I use watir in RadRails IDE. I need to attach a new window by
I'm new to Watir and I've having a little trouble getting logged in in
new here and new to jQuery. I've searched for an answer to my question/
New programmer here, I am trying to understand and break down this code below
New developer here,Im using the Custom Image Picker by ray wenderlich. But what I
I am new to Watir and I have this weird situation with AJAX based

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.