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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:16:01+00:00 2026-06-05T02:16:01+00:00

I have a written a Code in Selenium Web driver to test the health

  • 0

I have a written a Code in Selenium Web driver to test the health of the Contact Us page of my web site.

Code is working fine. My further aim is to:

  1. Use Rescue (to get error message when this scripts fail. Specifically when some element is not found during execution in the function > “def test_contact_us_screen_shot”).

Code for reference.

require 'rubygems'
require "selenium-webdriver"
require "test/unit"

class ContactUsScreenShot < Test::Unit::TestCase

  def setup
    @driver = Selenium::WebDriver.for :firefox
    @base_url = "http://www.mycompany.com"
    @driver.manage.timeouts.implicit_wait = 30
    @verification_errors = []
  end

  def teardown
    @driver.quit
    assert_equal [], @verification_errors
  end

  def test_contact_us_screen_shot
    @driver.get(@base_url + "/contact_us")
    #This method will take screenshot and  save it in the same folder from where script is executed.
    @driver.save_screenshot("./screen1.png")
    puts "screen shot taken"
    assert_equal "mycompany.com - Discuss your requirements to Outsource Software Product Development, Offshore Software Testing,", @driver.title
    @driver.find_element(:id, "compan").clear
    @driver.find_element(:id, "company").send_keys "My Company"
    @driver.find_element(:id, "first_name").clear
    @driver.find_element(:id, "first_name").send_keys "Mrityunjay"
    @driver.find_element(:id, "last_name").clear
    @driver.find_element(:id, "last_name").send_keys "Chauhan"
    @driver.find_element(:id, "email").clear
    @driver.find_element(:id, "email").send_keys "mrityunjay@gmail.com"
    @driver.find_element(:id, "phone1").clear
    @driver.find_element(:id, "phone1").send_keys "9999999999"
    @driver.find_element(:id, "addr1").clear
    @driver.find_element(:id, "addr1").send_keys "306 Office Address"
    @driver.find_element(:id, "addr2").clear
    @driver.find_element(:id, "addr2").send_keys "Office Address"
    @driver.find_element(:id, "city").clear
    @driver.find_element(:id, "city").send_keys "Dehradun"
    @driver.find_element(:id, "state").clear
    @driver.find_element(:id, "state").send_keys "UK"
    Selenium::WebDriver::Support::Select.new(@driver.find_element(:id, "country")).select_by(:text, "India")
    @driver.find_element(:id, "zip").clear
    @driver.find_element(:id, "zip").send_keys "248001"
    @driver.find_element(:id, "website").clear
    @driver.find_element(:id, "website").send_keys "http://www.mycompany.com"
    @driver.find_element(:id, "comments").clear
    @driver.find_element(:id, "comments").send_keys "This is the Testing Script for Contact Us page. Please Ignore.\nThanks,\nMrityunjay Chauhan"
    @driver.find_element(:name, "submit").click
    assert_equal "mycompany.com - Discuss your requirements to Outsource Software Product Development, Offshore Software Testing,", @driver.title
    begin
      rescue Exception => e
      puts e.message
      @driver.save_screenshot("./error1.png")
  end
  puts "I am Here"
    end

   def element_present?(how, what)
    @driver.find_element(how, what)
    true
  rescue Selenium::WebDriver::Error::NoSuchElementError
    false
  end

  def verify(&blk)
    yield
  rescue Test::Unit::AssertionFailedError => ex
    @verification_errors << ex
  end
end
  • 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-05T02:16:02+00:00Added an answer on June 5, 2026 at 2:16 am

    Following Rescue code is working fine in my code…

    rescue Exception => e
            puts e.message
            puts "Element Not Found"
            @driver.save_screenshot("./Test-Results/Contact_Us_Error.png")
            puts "I am Here"
        end #rescue
    

    In rescue we can trace the errors by using Log. For this we have to generated log file. Code is given below:

    First define log at the start of your code as:

    # Here I have created a log file in my "Test-Result" folder
    $log = Logger.new('./Test-Results/logfile.log')
    

    Next, we will move the error message to our log file using code given below:

    rescue Exception => e
                $log.error "This is the Error occurred when Element/s not found: #{e}"
                @driver.save_screenshot("./Test-Results/Contact_Us_Error.png")
                puts "I am Here"
            end #rescue
    

    Log will be something like this:
    E, [2012-06-04T16:03:44.546875 #796] ERROR — : Error in Elements when not found!: Unable to locate element: {“method”:”id”,”selector”:”compan”}

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

Sidebar

Related Questions

I have written an Ant target that starts Selenium server, runs my test code,
I have written code in Java to access web cam,and to save image... I
I have written code in C# which is exceeding page width, so I want
I'm working on a project and have written code that determines how much money
I have written code that opens 16 figures at once. Currently, they all open
I have written code to perform a function that could take a while to
Hi I have written code like this @Id @Column(nullable=false) @GeneratedValue(strategy=GenerationType.AUTO) public int getUserID() {
I have written some code for playing a .wav through my application. Now I
I have written this code to join ArrayList elements: Can it be optimized more?
I have written some code to ensure that items on an order are all

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.