I have an element in my code that’s used on many pages in many places. Specifically, it’s a calendar element. This element contains many parts, however, these internal parts are always the same no matter where it’s used. What I would like to do is search for something internal to the calendar element regardless of where the calendar element is.
Just as a simplified case, consider the following:
<div class="not-calendar">
<a href="/not-calendar-link">A Link</a>
</div>
<div class="calendar">
<a href="/calendar-link">A Link</a>
</div>
Now, I would like to do something along the lines of:
$this->click("//a[text()='A Link']");
But this is ambiguous. I would like to do that same kind of “search” for the A Link text, but only search for such within the div with the class calendar. Keeping in mind that I don’t want a direct XPath to the calendar div because I’m expecting it to show up in different places on many pages. How might I go about doing this? Thank you much!
Xpath is quite powerfull, have you tried to check the documentation?
The expression you’re looking for:
//div[@class='calendar']/a