Given this is my DOM, and it doesn't belong to me so I may not modify it in any way, how do I select the correct "click here" link based on the product-id inner text? Note that there are 3 products in this code and the link can appear at any place in the page so I must be able to select solely based on product-id. This is for a behat/mink functional test for PHP and so far every attempt I have made to select based on product id has failed.
<div id = "container">
<div class = "product">
<div class="product-detail">
<span class = "product-id">123-456-789</span>
</div>
<div class = "leftblock">
<div class = "product-info">
<a><span>Click Here</span></a>
</div>
</div>
</div>
<div class = "product">
<div class="product-detail">
<span class = "product-id">456-789-012</span>
</div>
<div class = "leftblock">
<div class = "product-info">
<a><span>Click Here</span></a>
</div>
</div>
</div>
<div class = "product">
<div class="product-detail">
<span class = "product-id">345-678-901</span>
</div>
<div class = "leftblock">
<div class = "product-info">
<a><span>Click Here</span></a>
</div>
</div>
</div>
</div>
This xpath, for example, has failed:
//span[text()='Click Here']/following::span[@class='product-id' and text()='" . $productId . "']
I've tried using ancestor and other things but nothing yet. I'm not even sure if I am using the correct characters. Any ideas?