WebDriver select element that has :: before

I have two elements that have the same attributes but are shown one per page (when one is displayed, the other disappears). The only difference between the two is that the displayed item will have :: before 'selector. Is it possible to use the xpath or css selector to retrieve an element based on its identifier and whether it has :: before

enter image description here

+7
source share
3 answers

I also put it to try using the javascript solution above.

:: after :: before , CSS ( HTML). DOM, , , xpath, (https://css-tricks.com/almanac/selectors/a/after-and-before/).

, , DOM xpath, / , .

+4
String script = "return window.getComputedStyle(document.querySelector('.analyzer_search_inner.tooltipstered'),':after').getPropertyValue('content')";
                        Thread.sleep(3000);
                        JavascriptExecutor js = (JavascriptExecutor) driver;
                        String content = (String) js.executeScript(script);
                        System.out.println(content);
0

CSS - - . :


::

::after - , CSS ( HTML). DOM, , , :

CSS:

div::after {
  content: "hi";
}

HTML:

<div>
  <!-- Rest of stuff inside the div -->
  hi
</div>

::

::before - , HTML, . :

  • , .
  • ::after "after" , ::before .

:

  • : content: "a string"; - Unicode. .
  • : content: url (/path/to/image.jpg); - . , , , .
  • : : ""; - ( , ).
  • Counter: content: counter(li);- Really useful for making lists until a marker appears.

Note : you cannot insert HTML (at least it will display as HTML).

content: "<h1>nope</h1>";
-2
source

Source: https://habr.com/ru/post/1583754/


All Articles