0

I have one <div> class having <a> tag and <h3> tags and the same <div>. I just wanted to click <a> of that div class based on <h3> text.

As per below example, div class name is "product eq-height" having <h3> tag who has some text "Applet Iphone 5S" if this result found then click on <a> class named "select-device-button".

But this div class comes multiple times with different H3 text on the page.

<div class="product eq-height" style="padding-bottom: 0px ! important; min-height: 329px;">
                    <h3 class="h4">Apple Iphone 5S</h3>

                    <input name="productModel" value="Apple Iphone 5S" type="hidden">
                    <div class="subtitle">
                      <span>Apple</span>
                    </div>
                    <a class="select-device-button" href="javascript:void(0);">
                      <div class="item">
                        <img alt="" class="prod-img-lrg lazyloaded" data-src="https://vgeco-oat1.vodafone.com/images/Iphone 5S.jpg" src="https://vgeco-oat1.vodafone.com/images/Iphone 5S.jpg"> <noscript><img alt="" src="https://vgeco-oat1.vodafone.com/images/Iphone 5S.jpg"&gt;</noscript>
                      </div></a>

                      <div class="info">
                        <div class="inner">
                          <ul class="cost">
                            <li><b>Total cost</b>
                            </li>


                            <li class="price">£ 300.00</li>
                          </ul>


                          <ul class="cost">
                            <li><b>My cost</b>
                            </li>

                                                                                                                <li class="price">£ 106.99</li>                            
                          </ul>
                        </div>


                        <div class="cta">
                          <a class="btn btn-sml select-device-button" href="javascript:void(0);">Select</a>
                        </div>
                      </div>


                      <div class="co-link-wrap txt-center">
                      </div>
                    </div>
1
  • How many h3 tags are there in your div?? Commented Feb 4, 2016 at 13:20

3 Answers 3

2

This is one possible XPath expression :

//div[@class='product eq-height' and h3='Apple Iphone 5S']/a[@class='select-device-button']

explanation :

  • //div[@class='product eq-height' and h3='Apple Iphone 5S'] : The above XPath will first find div element where class attribute value equals "product eq-height" and has child h3 with value equals "Apple Iphone 5S".

  • /a[@class='select-device-button'] : Then from found div elements, the XPath returns child element a where class attribute value equals "select-device-button".

Sign up to request clarification or add additional context in comments.

Comments

1

If i understood correctly you want to find an a element through certain div and h3, if yes then it you can do it pretty straightforward like so:

//div[h3[text()="Apple Iphone 5S"]]/a[@class="select-device-button"]

You are looking for div element that has certain h3 element and from there it's very easy to find the next element you want by using it's class attribute or any other that you need/want.

Hope this helps!

Comments

0

lets assume you have structure like..

<div>
<h3>Xyz</h3>
<a>Something there</a>
</div>

and you want to click on <a> tag when h3 is clicked

try to give a data attribute to h3 same to the id of a and then when user click on h3and get that data attribute in java script (attr("data")) and then click it through java script

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.