Xpath: select div that contains class AND whose specific child element contains text

Andrejs

With the help of this SO question I have an almost working xpath:

//div[contains(@class, 'measure-tab') and contains(., 'someText')]

However this gets two divs: in one it's the child td that has someText, the other it's child span.

How do I narrow it down to the one with the span?

<div class="measure-tab">
  <!-- table html omitted -->
  <td> someText</td>
</div>

<div class="measure-tab">  <-- I want to select this div (and use contains @class)
  <div>
    <span> someText</span>  <-- that contains a deeply nested span with this text
  </div>
</div>
nwellnhof

To find a div of a certain class that contains a span at any depth containing certain text, try:

//div[contains(@class, 'measure-tab') and contains(.//span, 'someText')]

That said, this solution looks extremely fragile. If the table happens to contain a span with the text you're looking for, the div containing the table will be matched, too. I'd suggest to find a more robust way of filtering the elements. For example by using IDs or top-level document structure.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

JQuery: find element whose class contains value of variable

From Dev

select matching elements whose sibling element has a specific class

From Dev

Use goquery to find a class whose value contains whitespace

From Dev

find elements by class whose id contains a substring and change the style

From Dev

CSS selector for a child element whose parent element has a certain class

From Dev

Access specific child class functions whose objects are in a template class vector

From Dev

Does it violate the MVC pattern's separation of concerns if a model class contains a static method whose parameters are instances of a View object?

From Dev

CSS: select a class whose name has a space?

From Dev

Select elements whose class ends with particular string

From Dev

Best way in python to make a class that is uninitializable but whose child classes are initializable

From Dev

How to generate a class using JAXB whose element can contain a string or XML?

From Dev

Find the header row element in table whose th cells have a class called 'headerClass'

From Dev

How to select tables in scrapy using selectors whose class id have spaces in it?

From Dev

mixin whose super class is not Object

From Dev

Unserialize class whose definition has changed

From Dev

Add class to jqgrid column whose type is checkbox

From Dev

Create a Class whose object can not be created

From Dev

Persisting an Object Whose Base Class is Not @Entity

From Dev

Printing a list whose elements are class objects

From Dev

Unserialize class whose definition has changed

From Java

Why can I not instantiate a class whose constructor is private in a friend class?

From Dev

Map a class to a generic whose parameter is the same the class's parameter

From Dev

How to create StringVar in a class whose Tk() is defined in some other class?

From Dev

C++ virtual inheritance and access to a public virtual method whose implementation is in a class whose inheritance is protected

From Dev

Calling object destructor whose type is nested inside of a class?

From Dev

How do you declare a variable for a class whose constructor takes an rvalue?

From Dev

How do I create an EAttribute whose data type is not an EMF class?

From Dev

Python: Dynamically adding function to a class, whose name is contained in a string

From Dev

Call known function (with parameters) in class whose name is defined by string variable

Related Related

  1. 1

    JQuery: find element whose class contains value of variable

  2. 2

    select matching elements whose sibling element has a specific class

  3. 3

    Use goquery to find a class whose value contains whitespace

  4. 4

    find elements by class whose id contains a substring and change the style

  5. 5

    CSS selector for a child element whose parent element has a certain class

  6. 6

    Access specific child class functions whose objects are in a template class vector

  7. 7

    Does it violate the MVC pattern's separation of concerns if a model class contains a static method whose parameters are instances of a View object?

  8. 8

    CSS: select a class whose name has a space?

  9. 9

    Select elements whose class ends with particular string

  10. 10

    Best way in python to make a class that is uninitializable but whose child classes are initializable

  11. 11

    How to generate a class using JAXB whose element can contain a string or XML?

  12. 12

    Find the header row element in table whose th cells have a class called 'headerClass'

  13. 13

    How to select tables in scrapy using selectors whose class id have spaces in it?

  14. 14

    mixin whose super class is not Object

  15. 15

    Unserialize class whose definition has changed

  16. 16

    Add class to jqgrid column whose type is checkbox

  17. 17

    Create a Class whose object can not be created

  18. 18

    Persisting an Object Whose Base Class is Not @Entity

  19. 19

    Printing a list whose elements are class objects

  20. 20

    Unserialize class whose definition has changed

  21. 21

    Why can I not instantiate a class whose constructor is private in a friend class?

  22. 22

    Map a class to a generic whose parameter is the same the class's parameter

  23. 23

    How to create StringVar in a class whose Tk() is defined in some other class?

  24. 24

    C++ virtual inheritance and access to a public virtual method whose implementation is in a class whose inheritance is protected

  25. 25

    Calling object destructor whose type is nested inside of a class?

  26. 26

    How do you declare a variable for a class whose constructor takes an rvalue?

  27. 27

    How do I create an EAttribute whose data type is not an EMF class?

  28. 28

    Python: Dynamically adding function to a class, whose name is contained in a string

  29. 29

    Call known function (with parameters) in class whose name is defined by string variable

HotTag

Archive