How to click one element when getting the error: Found 2 web elements with id

Hi, I use below script to click a “More” button

WebUI.click(findTestObject('HPSM/Page_HP Service Manager/button_More_Auto'))

But I got this error:

Found 2 web elements with id: ‘Object Repository/HPSM/Page_HP Service Manager/button_More_Auto’ located by ‘By.xpath: //button[@type = ‘button’ and @id != ‘ext-gen230’ and @class = ’ x-btn-text’ and (text() = ‘More’ or . = ‘More’)]’ in ‘30’ second(s)

In my case: The “More” button have dynamic id (it is auto-created at runtime), so I can’t find it by using id or xpath, and only find by text equal “More”, but there are 2 elements like that.

How can I click the first (or second) More button ?

Thank you very much !

Hi Bui,

you have to specify it in your XPath whether you want first or second button. Like this:

//first(//button[@type = 'button' and @id != 'ext-gen230' and @class = ' x-btn-text' and (text() = 'More' or . = 'More')])[1]// second(//button[@type = 'button' and @id != 'ext-gen230' and @class = ' x-btn-text' and (text() = 'More' or . = 'More')])[2]
1 Like

Thanks Marek Melocik,

I did as your said but still not successfully. Please see my image

Detail error

Test Cases/CreateNewTask FAILED because (of) Unable to click on object ‘Object Repository/HPSM/Page_HP Service Manager/button_More_Auto’ (Root cause: org.openqa.selenium.ElementClickInterceptedException: Element is not clickable at point (486.6083526611328,80) because another element

obscures it
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘T71DES55033’, ip: ‘192.168.122.2’, os.name: ‘Windows 8.1’, os.arch: ‘amd64’, os.version: ‘6.3’, java.version: ‘1.8.0_102’
Driver info: com.kms.katalon.core.webui.driver.firefox.CGeckoDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 61.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 11404, moz:profile: E:\TEMP\rust_mozprofile.fuw…, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 6.3, proxy: Proxy(direct), rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 66d6ec61-a092-4566-80d2-a3b4ebe0ba23)

And, I can’t search the element id “ext-gen396” and id “ext-gen410” in my web page

In actual, the second More button is: More

Error.png

As you can see in your error message - _Element is not clickable at point (486.6083526611328,80) **because another element

obscures it

**_It looks like there is some div on your page, which is obscuring your button. Try to click this div instead of button itself.

Marek Melocik said:

Hi Bui,

you have to specify it in your XPath whether you want first or second button. Like this:

//first(//button[@type = 'button' and @id != 'ext-gen230' and @class = ' x-btn-text' and (text() = 'More' or . = 'More')])[1]// second(//button[@type = 'button' and @id != 'ext-gen230' and @class = ' x-btn-text' and (text() = 'More' or . = 'More')])[2]

@Marek Melocik : How can I specify if I use Attribute text, not xpath ?

//label[(text()
= ’ 122 - NHTMCP DT&PTVN-CN HA THANH ’ or . = ’ 122 -
NHTMCP DT&PTVN-CN HA THANH ')]