2

I have tried with the xpath like "//HTMLtag[contains(text(),'Yourtext') and contains(text(),'Yourtext')]", but this case worked for the particular html tag and not for the different tags. how to make it to work for different tags like "//HTMLtag[contains(text(),'Yourtext')] and

//HTMLtag[contains(text(),'Yourtext')]".

here is the HTML snippet. Have to select admin of group from the below code.

<div class="widget">
<div class="widget-body">
    <h3 class="h3b">Admin</h3>
    <h4 class="h4a">Group</h4>
</div>

<div class="widget-body">
    <h3 class="h3b">Admin</h3>
    <h4 class="h4a">Class</h4>
</div>
</div>

Any help is appreciated...!!!

4

You haven't explained the requirement very clearly, but perhaps the answer is

//div[h3='Admin' and h4='Group']

Note that you shouldn't use contains() to test whether a node contains some string, unless you specifically want to allow it as a substring: you should use the '=' operator. And you should avoid using text() to fetch the text nodes: this would fail to match, for example,

<h3><a href="...">Admin</a></h3>

It's nearly always better to match on the string-value of the element, which is what happens when you just select the element node as an operand of '='.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.