Why is Google Chrome not printing the text () of my XPath query?

I am trying to fetch the xpath query text, $x('//td[@class="first"]/a/text()')

in Chrome, but then when I run this command, I see text

and not the actual text value of the anchor links.

When I run s.toString()

I see[object Text],[object Text],[object Text],[object Text]...

How can I get their string value in the xpath?

+5


source to share


1 answer


Because it $x()

returns an array of HTML or XML elements that match the given XPath expression. This means that this is actually a shortcut for document.evaluate (). So if you want to get the exact element, just get it by position from the array

$ X (element) [0]

This will help: https://developers.google.com/web/tools/chrome-devtools/console/command-line-reference#xpath



If you want to print (or do other things) all the text elements found by the locator in the console - you can just call forEach

)

$x('//a/text()').forEach(function(el){console.log(el)})

      

+5


source







All Articles