How to click first element when getting the error: Found 3 web elements with sample xpath ?


#1

There are some objects that have sample xpath, so I used [1], [2]
in xpath to get first or second element but not successfully. How can I
do that ?

//label[(text()
= ’ 117 - NHTMCP DT&PTVN-CN BINH DIEN SAI GON ’ or . = ’ 117 -
NHTMCP DT&PTVN-CN BINH DIEN SAI GON ')][1]

The error detail:

Found
3 web elements with id: ‘Object Repository/Page_SWIFT EDITOR
3.0/label_122 - NHTMCP DTPTVN-CN H’ located by 'By.xpath:
//label[(text() = ’ 117 - NHTMCP DT&PTVN-CN BINH DIEN SAI GON ’
or . = ’ 117 - NHTMCP DT&PTVN-CN BINH DIEN SAI GON ')][1]
’ in ‘30’ second(s)


#2

Hi Bui,
You might want to try
xpath: (//label[(text() = ’ 117 - NHTMCP DT&PTVN-CN BINH DIEN SAI GON ’ or . = ’ 117 - NHTMCP DT&PTVN-CN BINH DIEN SAI GON ')])[1]


#3

Hi Bui,
You might want to try
xpath: (//label[(text() = ’ 117 - NHTMCP DT&PTVN-CN BINH DIEN SAI GON ’ or . = ’ 117 - NHTMCP DT&PTVN-CN BINH DIEN SAI GON ')])[1]


#4

Similar to Hansen’s with a little betterment:

//label[(contains(text() , '117 - NHTMCP DT&PTVN-CN BINH DIEN SAI GON')][1]