Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in RPA by (12.7k points)

Hi All,

I am trying to write the relative expression(XPath) to get the card details from the following website

https://www.fakenamegenerator.com/gen-random-us-us.php

I see that the card name keeps alternating between VISA and MasterCard,

I wanted to know if the following expression is possible

"//dl[dt/text()='MasterCard']/dd OR //dl[dt/text()='Visa']/dd"

Can I use OR operator to make the expression generic so that it will work for both the cases VISA or Master Card?

FYI this is for an Automation Anywhere project where I am practicing to enhance my skills in WEB Automations

1 Answer

0 votes
by (29.5k points)

You cannot use the or operator like that. It is used when you want to have multiple predicate conditions. If you would like to have multiple possible node results like in your example then you should use a pipe | operator

//dl[dt/text()='MasterCard']/dd | //dl[dt/text()='Visa']/dd

 Using the pipe operator basically means that you are doing multiple searches rather than a single complex one.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...