Reputation: 79
I have HTML with different div's an span's inside:
<div class="test1">
<div class="test2">
<span title="Time">Today 11:12am</span>
</div>
<div class="test3">
<span class="test4">Windows 7 64 bit</span>
<span class="test5">Something</span>
</div>
</div>
<div class="test6">
<div class="test2">
<span title="Time">Today 11:15am</span>
</div>
<div class="test3">
<span class="test4">Windows 8 64 bit</span>
<span class="test5">Something</span>
</div>
</div>
I want to find an elements using XPATH by choosing a particular text from different span's. For instance, I need to find an element where is true : "Today" text and "Windows 7" text.
So, I've tried this statement :
//div[@class="test1"]/div[contains(span,'Today') and contains(span,'Windows')]
But this is not working. I've tried to use OR inside, it's working only for one true statement.
Are there others options?
Upvotes: 0
Views: 19399
Reputation: 25066
//div[.//span[contains(text(), 'Today')] and .//span[contains(text(), 'Windows 7')]]
Would work. The [expression]
you specify can literally be anything, so you can stuff another element search within there. The .
character is also key here, ensuring the search is scoped to the current parent (i.e the div
and not the entire document).
Upvotes: 2
Reputation: 79
I think I have found the solution. It can be :
//div[@class="test1"]/div[contains(span,'Today')]/following::div(span,'Windows')]
Upvotes: 0