Hey guys,
I have an easy (erm) question. I’m playing with XPaths (awesome stuff!) and normally, I can look inside the div elements to find some other element.
For example my XPath is: "xpath=//*[@id=“cars”]/div[2]/span
This finds me the span (text) which is inside the second div inside a div with an id “cars”. So far so good…
But, how would I write an XPath if I want to get to a span that is not inside the “cars” div but it’s outside of it?
When I use the inspector in the developer tools in Chrome, I can see that on the website there’s a div with id “cars”, then below there’s a div with some other things not interesting to me and then there’s the div with the span I want to get.
The hierarchy is like:
<body>
- some dynamic content that's always different -
<div id=cars>
<div>
<div>
<span>
I tried below (remembering how to work with directories in DOS )
xpath=//*[@id=“cars”]/…/div[2]/span
But that doesn’t seem to work.
And to make things more interesting, how would I write it if the “cars” div was inside one more div?
Like this:
<body>
- some dynamic content that's always different -
<div>
<div id=cars>
<div>
<div>
<span>
Thanks a lot for help!