0

For example :

<html >
  <body>
    <a class="abcd" title="he is Gandhi"> he was good </a>
    <a class="bcde" > he was very good </a>
    <a class="abcde" title ="Gandhi was "> good man </a>
  </body>
</html>

if here we want to display text in the above html where class="abcde" and title contains Gandhi using xpath in python how shall I do?

1

You can filter based on class and title attributes like:

//a[@class='abcde' and contains(@title, 'Gandhi')]

This part @class='abcde' will match for the exact class, then comes a logical and along with contains(@title, 'Gandhi') xPath function which should match any element with title containing 'Gandhi'.

The main point is that you can use and and or logical expressions in xPath expressions to be able to combine different attributes.

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.