From 083e99a8bb275e85eb2d55795e49c39a035c5f2d Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Fri, 24 May 2024 13:27:38 +0200 Subject: [PATCH] Add single click by id (#2135) --- lib/core/engine/command/mouse/singleClick.js | 41 +++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/core/engine/command/mouse/singleClick.js b/lib/core/engine/command/mouse/singleClick.js index ac8e367c6..974d4813d 100644 --- a/lib/core/engine/command/mouse/singleClick.js +++ b/lib/core/engine/command/mouse/singleClick.js @@ -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. @@ -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} 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} 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); + } + } }