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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:30:17+00:00 2026-05-25T11:30:17+00:00

I’m trying to scrape a span element that has mixed content <span id=span-id> <!–starts

  • 0

I’m trying to scrape a span element that has mixed content

<span id="span-id">
  <!--starts with some whitespace-->
  <b>bold title</b>
  <br/>
  text here that I want to grab....
</span>

And here’s a code snippet of a grab that identifies the span. It picks it up without a problem but the text field of the webelement is blank.

IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://page-to-examine.com");
var query = driver.FindElement(By.XPath("//span[@id='span-id']"));

I’ve tried adding /text() to the expression which also returns nothing. If I add /b I do get the text content of the bolded text – which happens to be a title that I’m not interested in.

I’m sure with a bit of xpath magic this should be easy but I’m not finding it so far!! Or is there a better way? Any comments gratefully received.

  • 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-25T11:30:18+00:00Added an answer on May 25, 2026 at 11:30 am

    I’ve tried adding /text() to the expression which also returns nothing

    This selects all the text-node-children of the context node — and there are three of them.

    What you refer to “nothing” is most probably the first of these, which is a white-space-only text node (thus you see “nothing” in it).

    What you need is:

    //span[@id='span-id']/text()[3] 
    

    Of course, there are other variations possible:

    //span[@id='span-id']/text()[last()] 
    

    Or:

    //span[@id='span-id']/br/following-sibling::text()[1] 
    

    XSLT-based verification:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="node()|@*">
         "<xsl:copy-of select="//span[@id='span-id']/text()[3]"/>"
     </xsl:template>
    
    </xsl:stylesheet>
    

    This transformation simply outputs whatever the XPath expression selects. When applied on the provided XML document (comment removed):

    <span id="span-id">
        <b>bold title</b>
        <br/>
        text here that I want to grab....   
    </span>
    

    the wanted result is produced:

         "
        text here that I want to grab....   
    "
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.