TestProject Forum
Powered by leading experts in the test automation community

Using xpath in chrome developers tools to get element value

For example if i go to Amazon.com and search for “LG G4”, i would like to get the value for the price of first item :
http://www.amazon.com/s/ref=nb_sb_noss_1/176-6904431-8522823?url=search-alias%3Daps&field-keywords=lg+g4

So, in chrome developer tools console i can get that element with xpath :

$x('//*[@id="result_0"]/div/div[4]/div[1]/a/span')[0]

But i am unable to retrieve the actual price value “$14.49”
I tried everything
$x(’//*[@id=“result_0”]/div/div[4]/div[1]/a/span’)[0].val val() value,text,html.

Any idea what i’m doing wrong ?

The problem is that $x() is only part of Chrome’s developer tools and not JavaScript.

Therefore you cannot invoke JavaScript functions on it.

try using vanilla JavaScript and by className to get price of first item:

document.getElementsByClassName('a-size-base a-color-price s-price a-text-bold')[0].innerHTML