1

I want to get tr element which contains span.selected in correct column. I need to do it using one selector.

It finds if element exists:

By.CssSelector("tr[role='row'].jqgrow td[aria-describedby$='Default'] span.selected")

but it return span.selected IWebElement.. How can I get tr[role='row'].jqgrow IWebElement (using CssSelector or XPath)?

nirmus
  • 4,733
  • 8
  • 29
  • 50

2 Answers2

3

Something like this may work with XPath

//tr[@role='row']
    [contains(@class, 'jqgrow')]
    [.//td[ends-with(@aria-describedby, 'Default')][.//span[contains(@class, 'selected')]]]

If elements have multiple classes, it's safer (and less readable) to replace the various contains(@class, 'jqgrow') with (@class and contains(concat(' ', normalize-space(@class), ' '), ' jqgrow ')) (trick borrowed from Python's cssselect)

I don't think you can achieve that with CSS selectors alone.

BoltClock
  • 665,005
  • 155
  • 1,345
  • 1,328
paul trmbrth
  • 19,928
  • 4
  • 48
  • 64
2

I do not believe CSS lets you do that, as you need a parent selector:

CSS selector for "foo that contains bar"?.

You will need to use XPath, which has the ability to select parents based on a child. You can check this post for information on using an XPath to select a parent with a specific child node:

XPath find all elements with specific child node

Community
  • 1
  • 1
Nathan Dace
  • 1,545
  • 9
  • 21