Found 2 web elements with id


I am getting 2 web element with same name and id so how can i choose second element?


This means your source HTML is invalid.

You should pass this back to the team that wrote the HTML, tell them it’s not valid to have more than one element with the same ID.


I agree with Russ 100%. As stated in the HTML specification (3.2 Elements — HTML5), the id value must be unique amongst all the IDs in a HTML.

But it would worth knowing how to choose the 2nd node of a node-set identified by the same ID.

Let me assume the target HTML is as such:

<div id="node">text 1</div>
<div id="node">text 2</div>
<div id="node">text 3</div>

Then you would have a set of Test Objects:

  • Page_6949/div_text1
  • Page_6949/div_text2
  • Page_6949/div_text3

Each of these Test Objects would have selector by xpath. For example, the div_text2 should have following selector:


This xpath expression is what you need. It selects the 2nd node in the node-set identified by //div[@id=“node”]

You should check off “tag”, “id”, “text” factors as these are not necessary. “xpath” factor is enough.

Then you would want to write you test case as follows:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
WebUI.verifyElementText(findTestObject('Page_6949/div_text 1'), 'text 1')
WebUI.verifyElementText(findTestObject('Page_6949/div_text 2'), 'text 2')
WebUI.verifyElementText(findTestObject('Page_6949/div_text 3'), 'text 3')

This test case would succeed.


1 Like