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?

Bence Kaulics
1,00712 silver badges22 bronze badges
asked Jan 5, 2019 at 11:43

1 Answer 1

2

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.

answered Jan 5, 2019 at 12:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.