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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:19:43+00:00 2026-06-06T17:19:43+00:00

I have the following html code: I saw that for Watir-webdriver the Watir::Image.file_size method

  • 0

I have the following html code:

I saw that for Watir-webdriver the “Watir::Image.file_size” method is not currently supported.
I found out that the “Watir-Classic/Image.rb” has the same method, and it seems that can be used.

# this method returns the filesize of the image, as an int
def file_size
  assert_exists
  @o.invoke("fileSize").to_i
end

I created a method that should retrieve the image size, but it seems I am not initializing the object correctly. Here is my code from the method:

img_src="/location/on_the_server/image"
chart_image = Watir::Image.new(:src, img_src)
puts chart_image.file_size

The problem is that I receive the following error:

"ArgumentError: invalid argument "/location/on_the_server/image""

I saw that for initialization the object requires (container,specifiers). I tried to change the initialization line to “chart_image = Watir::Image.new(img_src, :src)” but the error keeps appearing.

Could anyone tell me what am I doing wrong?

Is there another way to get the file size of an image from a website?

Thank you.

  • 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-06T17:19:45+00:00Added an answer on June 6, 2026 at 5:19 pm

    You should not be initializing Watir::Image directly. Instead, you should use the image() method of a browser or element object.

    #Assuming that browser = Watir::Browser that is open
    img_src="/location/on_the_server/image"
    chart_image = browser.image(:src, img_src)
    puts chart_image.file_size
    

    Update – Download Image to Determine File Size:

    You could download the image using with open-uri (or similar) and then use Ruby’s File class to determine the size:

    require 'watir-webdriver'
    require "open-uri"
    
    #Specify where to save the image
    save_file = 'C:\Users\my_user\Desktop\image.png'
    
    #Get the src of the image you want. In this example getting the first image on Google.
    browser = Watir::Browser.new
    browser.goto('www.google.ca')
    image_location = browser.image.src
    
    #Save the file
    File.open(save_file, 'wb') do |fo|
      fo.write open(image_location, :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read
    end
    
    #Output the size
    puts File.size(save_file).size
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML code: <div class=outer_container> <div id=imgContainer> <img src=/some/image /> </div>
I have the following HTML code: <div style=background-image:url(~/Images/MyImage.jpg); width:100%; height:100%> I'm not too familiar
I have the following HTML/JS/jQuery Code. This code represents a login form that is
I have the following html code: <form> <table> <tbody> <tr> <td> <span>Quantity<span class=pull-right>3</span> <input
I have the following html code with Jquery Sorting <div class=sortable style='width:700px; margin: 0
I have the following html code. <html> <body> <div style=max-width:1600px; min-width:900px; > <table> </table>
I have the following html code (in the given order) <div id=content>...</div> <div id=footer>...</div>
I have the following HTML code based on a tab menu format, i.e: <div
I have the following html code: <mytag> Just Some Text </mytag> And I have
I have the following HTML Code <%@ Page Language=C# %> <html> <head> <title></title> </head>

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.