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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:38:31+00:00 2026-06-18T02:38:31+00:00

I’ve got html like <div class=header><div class=title>AAAAAAAAA</div></div> <div class=body> <div class=card><div class=xxx><div class=yyy><div class=title>AAAAAAAAA</div></div></div></div>

  • 0

I’ve got html like

<div class="header"><div class="title">AAAAAAAAA</div></div>
<div class="body">
  <div class="card"><div class="xxx"><div class="yyy"><div class="title">AAAAAAAAA</div></div></div></div>
  <div class="card"><div class="xxx"><div class="yyy"><div class="zzz"><div class="title">BBBBBBBBB</div></div></div></div></div>
</div>

What I need to do to say (through watir-webdriver) “get me the element with class of ‘title’ and with text ‘AAAAAAAAA’ that is a child of an element with class ‘card’“. In this example, I want to find the div with class ‘title’ on the third line.

Its not enough to say “give me the element with text ‘AAAAAAAAA’ and class of ‘title’” because that element may exist somewhere else in the DOM. I have to be able to identify it by its attributes, and its parents.

I’m not sure how to do this, and would really love some suggestions.

In watir-webdriver, if I write:

b.element(:class => "card").element(:class => "title", :text => "BBBBBBBBB")

Then, from what I have seen, nothing will be found, as element(:class => “card”) will match the first card element, on line 3, and then the match for BBB… text will fail, because its only AAA… thats available under the first card.

I though of doing something like

b.elements(:class => "card").each { |elem| ...etc }

to find the child element I’m after, but when I find the child element, I can’t use it easily. For instance, I want to be able to call visible? on it, but the result is hard to get out of that code block. I could have a local variable that I assign the visible? result to, or I could throw an error from within the block, but its not really what I’m after.

What I’m really after is:

b.elements(:class => "card").element(:class => "title", :text => "BBBBBBBBB").othermethods...

So the first method call finds all elements with class of card, and then in the second method it finds the first element under those cards that has class “title” and text “BBBBBBBBB”. I know that there will be only one element with class ‘title’ and text “BBBBBBBBB” under a card.

However this functionality doesn’t exist. Is there an easy way to achieve the same thing? I’d really appreciate a bit of guidance here. Thanks in advance.

  • 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-18T02:38:32+00:00Added an answer on June 18, 2026 at 2:38 am

    I won’t be surprised if Justin or Željko come up with a better solution for you (and if they do then I’d like to know what it is, myself!), but here’s something that, while ugly, should suffice:

    target_parent_div = b.divs(class: "card").find { |div| div.div(class: "title", text: "AAAAAAAAA").exists? }
    target_element = target_parent_div.div(class: "title", text: "AAAAAAAAA")
    

    …Then use target_element for whatever you need.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
i got an object with contents of html markup in it, for example: string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a

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.