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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:57:58+00:00 2026-05-19T12:57:58+00:00

Given the following HTML page: <html> <head> <title>WatiN Test</title> </head> <body> <div> <p>Hello World!</p>

  • 0

Given the following HTML page:

<html>
<head>
    <title>WatiN Test</title>
</head>
<body>
<div>
    <p>Hello World!</p>
</div>
</body>
</html>

I would like to be able to search for some text (lets say "World"), and get a reference to its parent element (in this case the <p> element).


If I try this:

var element = ie.Element(Find.ByText(t => t.Contains("World")))

or this:

var element = ie.Element(e => e.Text != null && e.Text.Contains("World"));

I get back the <html> element. This is consistent with the WatiN documentation for Element.Text which states: “Gets the innertext of this element (and the innertext of all the elements contained in this element)”.

Since all text within the page is contained within the <html> element, I’ll always get this back instead of the immediate parent.


Is there a way to get just the text immediately beneath an element (not the text within the elements contained by it)?

Is there another way of doing this?

Many thanks.

  • 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-05-19T12:57:59+00:00Added an answer on May 19, 2026 at 12:57 pm

    Bellow code will find first element inside the <body/> with text containing “World”. Elements which are classified as element containers and has child elements will be omitted.

    var element = ie.ElementOfType<Body>(Find.First()).Element(e =>
    {
        if (e.Text != null && e.Text.Contains("World"))
        {
            var container = e as IElementContainer;
            if (container == null || container.Elements.Count == 0)
                return true;
        }
        return false;
    });
    

    Note: You may wonder why I wrote ie.ElementOfType<Body>(Find.First()).Element instead of just ie.Element. This should work, but it doesn’t. I think it’s a bug. I wrote a post about it on WatiN mailing list and will update this answer when I receive the answer.

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

Sidebar

Related Questions

I have an HTML page like: <html> <head><title>Hello</title></head> <body> <div id=foo> <h6>9</h6> <h6>3</h6> <h6>5</h6>
Consider the following code: <html> <head></head> <body> <div id='test' class='blah'> <a href='http://somesite.com/' id='someLink'>click!</a> </div>
Given the following HTML on a page: <div class='test'> <p><span id='id1' class='test1 test2 test3'>test
I am using the following html page: <html> <head> <title>AJAX Example</title> <meta http-equiv=Content-Type content=text/html;
Given the following HTML <div style=width: 500px; height: 500px; border: 1px solid red;> <div
Given the following HTML <div classmyclass>10</div> <div classmyclass>25</div> <div classmyclass>50</div> <div classmyclass>20</div> I want
Given the following HTML example... <div id='div1'>div one</div> <div id='div2'>div two</div> ...I found that
Given the following HTML page a horizontal line appears at the top of the
I have the following file file: <html> <head> <title></title> <script type=text/javascript src=/Prototype.js></script> <script type=text/javascript>
I use the following datepicker.php page for jquery datepicker is given below: <!DOCTYPE html>

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.