How to create a single testobject with two or more Xpath for a single element?

I have an element on a page which has more than one xpath based on some criteria.
I want to create a single testobject containing all the xpaths of that element in OR clause.

So, If first xpath is not found, it will look for the 2nd xpath.

Is there any way to do it?

Pls help.

Thanks in advance!!!

1 Like

Hi there, :wave:

Thank you very much for your topic! It may take a little while before Katalon team member or others forum members respond to you.

In the meantime, you can double-check your post to see if you can add any extra information i.e. error logs, HTML codes, screenshots, etc. Check out this posting guide to help us help you better!

Thanks! :sunglasses:
Katalon Community team

Hi :slight_smile:

There are multiple solutions, it really depends on your specific situation.
It depends on how you apply them and how your DOM looks like, so the solutions will not accidentally match additional other elements with the other path when the first case is found.

  1. You can write it directly in the xpath with the OR operator. This will select every element that fulfills the first part AND every element that fulfills the second part separately.
    example: //*[@id='site-logo' or @id='site-logo-1']

  2. Other or operator |
    example: //book/title1 | //book/title2

  3. You can do it by using a variable in the xpath, and you specify in your code for example with an if statement which to use.
    example: //*[@id='${variable}']
    Use variables in Web test objects | Katalon Docs

These are really simple examples, but without seeing the specifics it is hard to say.
Hope this helps!

you can create a separate locator file with multiple xpaths/css and handle it in your code to fetch elements