0

I have a problem with some css selector (I have only one way to find an element if I use JS commands so only CSS selector is available for me) The page looks like this:

<div class='test'>
some_text
<span> some_other_text </span>
</div>

And I need to get some_text without getting "some_other_text"; I tried to use: By.CssSelector("div[class='test'] :not(span)") >> it returns all text; By.CssSelector("div[class='test'] span:not(last-child)") >> it returns only "some_other_text"; By.CssSelector("div[class='test'] span:not(:last-child)") >> it returns only "some_other_text"; By.CssSelector("div[class='test']:not(:last-child)") >> it returns only "some_other_text";

is there any way to do what I need? could anyone help me , please?

Danny '365CSI' Engelman
  • 16,526
  • 2
  • 32
  • 49
Kate
  • 33
  • 4
  • 1
    This isn't possible with CSS. `:not` isn't a filter for text content--just elements. – isherwood Oct 05 '21 at 15:20
  • Seconding @isherwood - the problem is that the element `.test` contains that content-- filtering out the `` inside only guarantees you won't get it returned as an element. If you can control your mark-up, you might consider wrapping "some_text" with an element you can select. – Alexander Nied Oct 05 '21 at 15:22
  • This would be fairly trivial with JavaScript, however. See https://stackoverflow.com/questions/58187674/how-to-get-only-directly-contained-text-in-dom-element-in-javascript. – isherwood Oct 05 '21 at 15:24

0 Answers0