0

The Error I am getting is Below: org.openqa.selenium.JavascriptException:javascript error:Failed to execute'getComputedStyle' on 'Window': parameter 1 is not of type 'Element' I am trying to find the element and get the color of it and the element is stored in DOM with ::before I am not getting this element color by using xpath for span please suggest what wrong with this code

String script = "return window.getComputedStyle(document.querySelector('.dot[_ngcontentephc8]'),':before').getPropertyValue('background')";
JavascriptExecutor jse = (JavascriptExecutor)Browser.getDriver();
String colorCode = (String) jse.executeScript(script);
System.out.println("colorCode);
String hexColorCode = convertBackgroundColorToHexFormat(colorCode);
System.out.println("hexColorCode);
return hexColorCode.equalsIgnoreCase(color);
Akshay
  • 1
  • 1
  • Can you add to the question the relevant part of HTML for the element you are trying to get? The part with the square brackets `[_ngcontentephc8]` doesn't seem valid to me – Kaddath Apr 19 '23 at 13:31
  • ::before --this is the element I am trying to get using javascriptexecuter – Akshay Apr 19 '23 at 13:32
  • `.dot[_ngcontentephc8]` means: select element with class "dot" and attribute "_ngcontentephc8". This doesn't seem to correspond to what you are trying to get, so the result is null, and `getComputedStyle` throws an error as expected.. – Kaddath Apr 19 '23 at 13:41
  • could you help how can i resolve the issue – Akshay Apr 19 '23 at 13:50
  • Are you sure this is the element rendered on your browser? The part `class="classname"` seems weird to me. Does it appear like this when you inspect it in your browser? – Kaddath Apr 19 '23 at 14:08
  • Yes it appears like this in span tag and in ::before . the before is showing the correct element but i am not able to locate that using xpath or jse – Akshay Apr 20 '23 at 09:24
  • The will looks like this and I want locate the ::before element ---> flex ::before – Akshay Apr 21 '23 at 06:38
  • Does it work with `'.dot[_ngcontent-cah-c8]'` then? – Kaddath Apr 21 '23 at 07:55
  • Actually no its not working with that script above mentioned – Akshay Apr 24 '23 at 05:41

0 Answers0