Skip to content

Commit

Permalink
Add single click by id (#2135)
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore committed May 24, 2024
1 parent bc34da6 commit 083e99a
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion lib/core/engine/command/mouse/singleClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class SingleClick {

/**
* Clicks on a link whose visible text contains the given substring and waits on the
* page complete checl.
* page complete check.
*
* @async
* @param {string} text - The substring of the visible text of the link to click.
Expand All @@ -247,4 +247,43 @@ export class SingleClick {
throw new Error('Could not find link by partial text ' + text);
}
}

/**
* Clicks on a element with a specific id.
*
* @async
* @param {string} id - The id of the link to click.
* @returns {Promise<void>} A promise that resolves when the click action is performed.
* @throws {Error} Throws an error if the id is not found.
*/
async byId(id) {
try {
const element = await this.browser.getDriver().findElement(By.id(id));
return this.actions.click(element).perform();
} catch (error) {
log.error('Could not find the element with id %s', id);
log.verbose(error);
throw new Error('Could not the element with id ' + id);
}
}

/**
* Clicks on a element with a specific id and wait on the page complete check
*
* @async
* @param {string} id - The id of the link to click.
* @returns {Promise<void>} A promise that resolves when the page has completed.
* @throws {Error} Throws an error if the id is not found.
*/
async byIdAndWait(id) {
try {
const element = await this.browser.getDriver().findElement(By.id(id));
await this.actions.click(element).perform();
return this.browser.extraWait(this.pageCompleteCheck);
} catch (error) {
log.error('Could not find the element with id %s', id);
log.verbose(error);
throw new Error('Could not the element with id ' + id);
}
}
}

0 comments on commit 083e99a

Please sign in to comment.