Using xpath in chrome developers tools to get element value

  • 1 Replies
  • 2326 Views
Using xpath in chrome developers tools to get element value
« on: February 18, 2016, 09:13:41 am »
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 :
Code
$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 ?

*

Oren

  • **
  • 59
Re: Using xpath in chrome developers tools to get element value
« Reply #1 on: February 18, 2016, 14:18:39 pm »
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:

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

 

Sitemap 1 2 3 4 5 6 7 8