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

  • Home
  • SEARCH
  • 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 8694759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:51:40+00:00 2026-06-13T00:51:40+00:00

I am using Selenium-WebDriver for Ruby and I am trying to verify that text

  • 0

I am using Selenium-WebDriver for Ruby and I am trying to verify that text is present on a page. I have done many searches and tried many things and the best answer I have found is to use something like

  def check_page(textcheck)
  if verify {@driver.find_element(:id=>"body").text.include?(textcheck)}
    yield it_to "fail"
  else
    yield it_to "pass"
  end
  end

The expected outcome if the value of textcheck is present in the body would be pass and if the value of textcheck is not present in the body it would be fail. What is actually happening is if :id=>”body” is present then it is pass and if it is not present then it is fail regardless of .text.include?(textcheck)

If anyone could point me in the right direction for how to verify text is present on a page using Selenium-WebDriver in Ruby it would be greatly appreciated. I have found workarounds for certain cases where I can do

verify {@driver.find_element(:tag_name, 'h1').text!=(textcheck)}

but the element I am trying to verify I can’t get to so easily. I looked into css locators and was very confused on how to simplify the tag so I could use it. Any help would be greatly appreciated. Thank you very much. If you require any more information from me please let me know and I will provide it as soon as possible.

I am using Ruby 1.93 with Selenium-WebDriver 2.25 testing in Firefox 14.0.1

  • 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-13T00:51:41+00:00Added an answer on June 13, 2026 at 12:51 am

    I do it this way

    @wait = Selenium::WebDriver::Wait.new(:timeout => 30)
    begin
      @wait.until { @driver.find_element(:tag_name => "body").text.include?("your text")}
    rescue  
      puts "Failure! text is not present on the page"
      #Or do one of the options below
      #raise
      #assert_match "true","false", "The text is not present"
    end
    

    UPDATE


    Answer to your question in the comments section.

    There are two kind of “waits”, implicit wait and explicit wait. You can read more about it here. The reason your code failed was because you were searching by “id”=>”body” and not by “tag_name”=>”body”. Usually all text is encompassed within the “body” HTML tags in your DOM.

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

Sidebar

Related Questions

I am trying a select a text from the Dropdown Menu using Selenium webdriver
I am trying to check to see if text is present using Selenium 2
So I'm trying to write a suite of tests using Selenium WebDriver in Ruby
I have some tests created using Selenium WebDriver. When I run them using IE
How can we get exact time to load a page using Selenium WebDriver? We
I have seen lots of questions and solutions on File upload using Selenium WebDriver
I am trying to set and then read a Cookie using the Selenium Webdriver.
I have a C# unit test using Selenium WebDriver to test to see if
I'm using Selenium Java 2.0b3 . I have this code: ... WebDriver driver =
I'm using selenium webdriver to test our website. We also have a browser plugin/extension

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.