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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:57:36+00:00 2026-06-18T16:57:36+00:00

There is a div on a page that is not visible but has some

  • 0

There is a div on a page that is not visible but has some value I want to capture. Calling text on it returns me an empty string.

How do I get the value displayed without having to deal with the raw html? Can I force .text to return me the actual value regardless of the visiblity of the text in the browser?

irb(main):1341:0> d.first.visible?
=> false

irb(main):1344:0> d.first.html
=> "<div class=\"day\">7</div>"

irb(main):1345:0> d.first.text
=> ""

PS: There are many many divs (the page is caching response and display them accordingly). I considered changing all the display:none in the page or clicking to make them visible but I’d prefer to avoid this if possible.
If not possible a solution with changing all the display none would be the preferred work around.

PPS: Damned, I tried to overload the visible? method in the Watir::Element class to always return true, but that didn’t do the trick.

irb(main):1502:0> d.first.visible?
=> true

irb(main):1504:0> d.first.text
=> ""
  • 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-06-18T16:57:37+00:00Added an answer on June 18, 2026 at 4:57 pm

    For the newer versions of Watir, there is now an Element#text_content method that does the below JavaScript work for you.

    e = d.first
    e.text_content
    #=> "7"
    

    For Old Versions of Watir (Original Answer):

    You can use JavaScript to get this.

    e = d.first
    browser.execute_script('return arguments[0].textContent', e)
    #=> "7"
    

    Note that this would only work for Mozilla-like browsers. For IE-like browsers, you would need to use innerText. Though if you are using watir-classic it would simply be d.first.innerText (ie no execute_script required).

    Using attribute_value:

    Turns out you can make it simpler by using the attribute_value method. Seems it can get the same attribute values as javascript.

    d.first.attribute_value('textContent')
    #=> "7"
    

    Using inner_html

    If the element only includes text nodes (ie no elements), you can also use inner_html:

    d.first.inner_html
    #=> "7"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey there, i have a div that expands when the page is loaded, now
my Page has many hover images, sometimes there are backgrounds from div-elements or src
I have a < div > in my aspx page which has some notification
I have an XHTML strict page that has an invisible div that is controlled
I've got three columns inside of a div that is the full page width.
I have created a div there are two childs of that div one is
there is a div with some values like this: <div id=links> <link1>||<link2>||<link3> </div> i
Here is my site: http://smartpeopletalkfast.co.uk/pos/ There is a div #nav which has a fixed
I have a page that has three divs one at the top, one at
I am working on a single page applications that has a bunch of hidden

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.