1

I'm trying to get css for below xpath

//*[@id="key-facts-heading"]/h4[1]/text()[2]

but couldn't understand what to do after #key-facts-heading

I don't understand why chrome console doesn't have css selector but it has xpath, is there another way to get css from chrome console directly ?

Note:

Earlier I was relying on https://cssify.appspot.com/ but this website is not more working with error "

Access to XMLHttpRequest ...from origin 'https://cssify.appspot.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

"

enter image description here

vikramvi
  • 3,312
  • 10
  • 45
  • 68

1 Answers1

1

Updated :

To get 2,43,078.87 Cr as the output,

// Target the element
WebElement element = driver.findElement(By.cssSelector("#key-facts-heading > h4:nth-of-type(1) > span"));
// Get the following text using a JS Executor
String text = (String)((JavascriptExecutor)driver).executeScript("return arguments[0].nextSibling.textContent.trim()", element);
System.out.println(text);

Note : 2,43,078.87 Cr is within <h4> and not <span>

Wilfred Clement
  • 2,674
  • 2
  • 14
  • 29