How do we use click element by ID

Hi All,

I tried clicking a button by passing its id (as xpath is not working ) but I dont understand why is it not working as expected .WebUI.doubleClick(findTestObject('Object Repository/Page_ACE Portal/button_Quarter Wise Report as', 'id')) this is how i written.

Also do I need to make any change in these section

Please let me know thanks !!

You can try so: //button[@id=‘something’]

EDIT: xpath:attributes - //button[@id=‘something’]

@Ankita_Raman Can you provide the HTML of the element you are trying to click? Thanks.

This is the html I am trying to refer:
<button class="btn btn-hero-primary btn-tn small-button" id="testKatalon" [nbPopover]="popContentExport" nbPopoverMode="hint" nbPopoverPlacement="left" (click)="exportToExcel('event')"> <i class="fa fa-file-excel-o" style="zoom:1.3;" aria-hidden="true"></i> <ng-template #popContentExport>Export to Excel</ng-template> </button>

try to use xpath:attributes - //button[@id=‘testKatalon’]

1 Like

Thanks for the HTML. First of all, to follow the suggestion made by @brithwulf, you should define your Test Object for the button as follows:

I also noticed that the path to your Test Object may be part of the problem. Try the following code instead (make sure you have the two import statements as well):

import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.doubleClick(ObjectRepository.findTestObject("Page_ACE Portal/button_Quarter Wise Report as"));

Notice the path to the Test Object does not include the ‘Object Repository/’ portion, as Katalon already assumes this because you are using the findTestObject() method.

Let us know if this helps!

1 Like

let me try this and get back to thanks @Brandon_Hein

Thanks @brithwulf I tried this but no luck !! :frowning_face:

Can you show me the error log ? What does it say

EDIT: You can also try to use ChroPath. It is a Google Chrome extension, which automatically gives you xpath attributes for your html code. And also in Object Repository check if in objects settings is XPath checked.
Also try to switch Web Locators to XPath Project->Settings-Test Design->Web Locators->Xpatch must be checked

@brithwulf for time being I have changed this complete set of code took a different way to get the solution as I had to deliver it by today Noon . Once again after my presentation I will open up and share the code with you guys . Thanks so much both of you .!!!:slightly_smiling_face::slightly_smiling_face::blush::blush:

1 Like