Home > OS >  What's the difference between this two FULL XPATH?
What's the difference between this two FULL XPATH?

Time:10-24

The link I used is here

My procedure of getting the "price" xpath are:

  1. go to the link using chrome
  2. use tool inspect element
  3. search for the price number
  4. then come into <span >some_numbers</span>
  5. right click the element, then select Copy Full XPATH
  6. Then I'll get /html/body/div[2]/div/div[1]/div[3]/div/div[2]/div[1]/div[2]/div[3]/div/div[2]/span[1]

Problem: Two days ago before this thread, I was using the full xpath I got from chrome inspection, it working just fine in xidel without a problem. But now,

xidel -se '/html/body/div[2]/div/div[1]/div[3]/div/div[2]/div[1]/div[2]/div[3]/div/div[2]/span[1]' ~/Desktop/document.html

or

xidel -se '/html/body/div[2]/div/div[1]/div[3]/div/div[2]/div[1]/div[2]/div[3]/div/div[2]/span[1]' https://www.cnbc.com/quotes/XAU=

gives me no output...

but, user2703456 given me the "correct" full xpath as follow /html/body/div[2]/div/div[1]/div[3]/div/div/div[1]/div[2]/div[3]/div/div[2]/span[1]

it solved the problem, however, I still confused. when I check both full xpath pointing at the same element, exact same element. why? why it was working before, but now wont?

XPath inspection snapshot

CodePudding user response:

I suppose it's content comes dynamicly, and somehow the server or javascript changes html.

To overcome this problems i would use not the copied XPath but rely more on a combination of @class en @id attributes i.e. like this:

//*[@id='quote-page-strip']//*[@class='QuoteStrip-lastPrice']
  • Related