GithubHelp home page GithubHelp logo

XPath 4 about dhclass-hub HOT 8 CLOSED

ebeshero avatar ebeshero commented on July 25, 2024
XPath 4

from dhclass-hub.

Comments (8)

ghbondar avatar ghbondar commented on July 25, 2024

2a. is pretty straight-forward (you should find 18 divs that contain "homework").
2b. involves identifying the parent of the element whose text-node has "homework". (you should retrieve 9 results). @amielnicki

from dhclass-hub.

nlottig94 avatar nlottig94 commented on July 25, 2024

I was having the same issues. I got the first expression, but I can't get the last expression. I tried: //div[contains(., "homework")]/.. but it is giving me 11 results instead of 9...

from dhclass-hub.

ghbondar avatar ghbondar commented on July 25, 2024

Your XPath is finding the parent of the div, not the parent of the element, that contains "homework".
The trick is to refer to the text-node containing "homework", first.
@nlottig94

from dhclass-hub.

ghbondar avatar ghbondar commented on July 25, 2024

Your XPath is finding the parent of the div, not the parent of the element, that contains "homework".
@nlottig94

from dhclass-hub.

nlottig94 avatar nlottig94 commented on July 25, 2024

I figured it out! Thanks!

from dhclass-hub.

spadafour avatar spadafour commented on July 25, 2024

I am still completely lost on 2b. Are we using text() in this? How do we refer to specific text if we cannot place actual text within text()?

This is the closest that I got:
//div[contains(., "homework")]/parent::*[contains(., "homework")]

but I know that is referring to the parent of the element. If I take it out, I get more results:
//div[contains(., "homework")]/*[contains(., "homework")]

from dhclass-hub.

ghbondar avatar ghbondar commented on July 25, 2024

Getting closer, now how about using text() as part of the element tree with a predicate, such as:
text()[contains(., 'homework')]
@spadafour

from dhclass-hub.

ghbondar avatar ghbondar commented on July 25, 2024

That way you only have to search for the homework once.

from dhclass-hub.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.