How do I select an element based on a data attribute?

I need to click on a div whose only unique attribute is data-category="overall" (using the elementclick selector). Then I need to get the text out of a child span under this element. How do I specify the data-category attribute to do both of these things?

div[data-category='overall'] > span
should do it.

Or if the span is not a direct child,
div[data-category='overall'] span

Ref: https://www.w3schools.com/cssref/css_selectors.asp

1 Like