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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:32:23+00:00 2026-06-11T04:32:23+00:00

Consider the following html as an example. its a scratch sheet I made to

  • 0

Consider the following html as an example. its a scratch sheet I made to practice, but it has a snippet of the real html I am trying to work with.

http://www.carbide-red.com/prog/test_table.html

I am trying to locate a column and the only consistant identifier I can find is the background color (bgcolor).

<tr bgcolor="#ffffcc">
    <td bgcolor="yellow" class="date" align=center>Equipment</td>
    <td bgcolor="#ccccff" align=center class="date"><font color=black>8/12/12</font></td>
    <td bgcolor="#ccccff" align=center class="date"><font color=black>8/19/12</font></td>
    <td bgcolor="#ccccff" align=center class="date"><font color=black>8/26/12</font></td>
    <td bgcolor="#ccccff" align=center class="date"><font color=black>9/2/12</font></td>
    <td bgcolor="red" align=center class="date"><font color=yellow>9/9/12</font></td>
    <td bgcolor="#ccffcc" align=center class="date"><font color=black>9/16/12</font></td>
    <td bgcolor="#ccffcc" align=center class="date"><font color=black>9/23/12</font></td>
    <td bgcolor="#ccffcc" align=center class="date"><font color=black>9/30/12</font></td>
    <td bgcolor="#ccffcc" align=center class="date"><font color=black>10/7/12</font></td>
</tr>

I’m trying to find the <td> that has bgcolor=red. I would then like to save the column index of that cell, so that I can then use it to select the same column of the following rows.

But I can’t seem to find a way to search for the bgcolor= tag. And I have not been able to find a way to get Watir to report back the column/row indexs to store in a variable. But if I can find the bgcolor= tag then I can search for like “equipment” and then count until I find the correct tag.

I know the html code is not ideal due to there note being any “name” or anything unique identifier, but I can’t change that.

I am very new to Ruby & Watir. I tried to manipulate a website in Perl and it was was not going very well, and I discovered Watir and it did exactly what I needed (and suprisingly easy), but now I am trying to understand Ruby as well as the finer semantics.

Thanks for any help!

  • 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-11T04:32:25+00:00Added an answer on June 11, 2026 at 4:32 am

    To get text of <td bgcolor="red"> try this:

    browser.element(:css => "td[bgcolor=red]").text
    

    You should get back "9/9/12". To click the element, replace text with click.

    To put it’s index in variable index try this:

    index = nil
    browser.tds.each_with_index {|td, i| index = i if td.attribute_value("bgcolor") == "red" or td.attribute_value("bgcolor") == "#ff0000"}
    

    index variable should be 5.

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

Sidebar

Related Questions

Consider the following example: ( live demo here ) HTML: <div class=board> <div class=row>
Consider the following HTML snippet. The desired effect is to have a dropdown be
Consider the following HTML snippet containing some javascript utilizing prompt and unload . The
Consider the following example: <html> <body> <script type=text/javascript> var str=filename.jpg; var pattOne = new
Consider the following example: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd> <html xmlns=http://www.w3.org/1999/xhtml
Consider the following example: ( live demo ) HTML: <div> <p> <strong>Stack</strong> <span>Overflow</span> </p>
Consider the following example: ( live demo here ) HTML: <label>Name</label> CSS: label {
Consider the following example code: http://code.google.com/apis/maps/documentation/javascript/examples/streetview-simple.html I can do scrollwheel: false on a mapOptions
Consider the following example: HTML: <div id=cool-div></div> JS/jQuery: var ComplexObject = function() { this.Append
Consider the following example: ( live demo ) HTML: <select> <option>Hello</option> <option>Stack</option> <option class=a>Overflow</option>

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.