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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:16:05+00:00 2026-05-12T08:16:05+00:00

today I stumbled upon a very interesting case (at least for me). I am

  • 0

today I stumbled upon a very interesting case (at least for me). I am messing around with Selenium and xPath and tried to get some elements, but got a strange behaviour:

<div class="resultcontainer">
   <div class="info">
     <div class="title">
        <a>
           some text
        </a>
     </div>
   </div>
</div>

<div class="resultcontainer">
   <div class="info">
     <div class="title">
        <a>
           some other text
        </a>
     </div>
   </div>
</div>

<div class="resultcontainer">
   <div class="info">
     <div class="title">
        <a>
           some even unrelated text
        </a>
     </div>
   </div>
</div>

This is my data.
When i run the following xPath query:

//div[@class="title"][1]/a

I get as a result ALL instead of only the first one. But if I query:

//div[@class="resultcontainer"][1]/div[@class="info"]/div[@class="title"]/a

I get only the first , not all.

Is there some divine reason behind that?

Best regards,
bisko

  • 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-12T08:16:06+00:00Added an answer on May 12, 2026 at 8:16 am

    I think you want

    (//div[@class="title"])[1]/a
    

    This:

    //div[@class="title"][1]/a
    

    selects all (<a> elements that are children of) <div> elements that have a @class of 'title', that are the first children of their parents (in this context). Which means: it selects all of them.

    The working XPath selects all <div> elements that have a @class of 'title' – and of those it takes the first one.

    The predicates (the expressions in square brackets []) are applied to each element that matched the preceding location step (i.e. "//div") individually. To apply a predicate to a filtered set of nodes, you need to make the grouping clear with parentheses.

    Consequently, this:

    //div[1][@class="title"]/a
    

    would select all <div> elements, take the first one, and then filter it down futher by checking the @class value. Also not what you want. 😉

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

Sidebar

Related Questions

Today I stumbled upon an interesting bug I wrote. I have a set of
Today I stumbled upon a rather interesting compiler error: int main() { int const
Today I was doing some leisurely reading and stumbled upon Section 5.8 (on page
Today I stumbled upon a case where I would readily assume a simple optimization
I stumbled upon something similar today, and subsequently tried a few things out and
Today while I was reading some documentation regarding the BigDecimal class, I've stumbled upon
I stumbled upon this oddity today while playing with some code to go down
I was doing some querying today in T-SQL, SQL-Server-2008 and stumbled upon something weird
I was messing around with the java.io.File methods today, and stumbled on something kind
Today I stumbled upon this thread: http://www.mathworks.com/matlabcentral/newsreader/view_thread/112560 The question is basically how to make

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.