click
codebolt.browser.click(elementid: string): Promise<ClickResponse>Clicks on a specified element on the page.
Parameters
| Name | Type | Description |
|---|---|---|
| elementid | string | The ID of the element to click. |
Response Structure
The method returns a Promise that resolves to a BrowserActionResponseData object with the following properties:
type(string): Always "clickResponse".payload(object, optional): Contains the response data including:action(string, optional): The action that was performedsuccess(boolean, optional): Indicates if the click was successfulcontent(string, optional): Additional content informationviewport(object, optional): Current viewport information
eventId(string, optional): Event identifier for the click actionsuccess(boolean, optional): Indicates if the operation was successfulmessage(string, optional): A message with additional informationerror(string, optional): Error details if the operation failedmessageId(string, optional): A unique identifier for the messagethreadId(string, optional): The thread identifier
Example
// Navigate to a page with interactive elements
await codebolt.browser.goToPage("https://example.com");
await new Promise(resolve => setTimeout(resolve, 2000));
// Click on a button with the ID "submit-btn"
const clickResult = await codebolt.browser.click("submit-btn");
console.log('✅ Clicked:', clickResult);
// Check if the click was successful
if (clickResult.success) {
console.log('Click action completed successfully');
} else {
console.error('Click failed:', clickResult.error);
}
// Click on a link with a specific ID
await codebolt.browser.click("nav-link");
// Click on a checkbox or radio button
await codebolt.browser.click("checkbox-id");
Notes
- The
elementidparameter must correspond to an existing element ID on the current page - The element must be visible and clickable for the operation to succeed
- The response provides confirmation of the click action and any relevant page state changes