From b87a0c397c5553441b6eb9e56e418c5dcec07cdd Mon Sep 17 00:00:00 2001 From: phpussente Date: Thu, 4 May 2023 14:43:19 -0300 Subject: [PATCH] new(basic.gblib): Command CLICK BUTTON --- packages/basic.gblib/services/KeywordsExpressions.ts | 8 ++++++++ .../basic.gblib/services/WebAutomationServices.ts | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/basic.gblib/services/KeywordsExpressions.ts b/packages/basic.gblib/services/KeywordsExpressions.ts index d6eea604..f8f67fd5 100644 --- a/packages/basic.gblib/services/KeywordsExpressions.ts +++ b/packages/basic.gblib/services/KeywordsExpressions.ts @@ -806,6 +806,14 @@ export class KeywordsExpressions { return `await wa.linkByText ({pid: pid, handle: page, ${params}})`; } ]; + + keywords[i++] = [ + /^\s*(click button)(\s*)(.*)/gim, + ($0, $1, $2, $3) => { + const params = this.getParams($3, ['text', 'index']); + return `await wa.clickButton ({pid: pid, handle: page, ${params}})`; + } + ]; keywords[i++] = [ /^\s*(click)(\s*)(.*)/gim, diff --git a/packages/basic.gblib/services/WebAutomationServices.ts b/packages/basic.gblib/services/WebAutomationServices.ts index 432b81b8..be5f4893 100644 --- a/packages/basic.gblib/services/WebAutomationServices.ts +++ b/packages/basic.gblib/services/WebAutomationServices.ts @@ -316,6 +316,18 @@ export class WebAutomationServices { await els[index - 1].click(); await this.debugStepWeb(pid, page); } + + public async clickButton({ pid, handle, text, index }) { + const page = WebAutomationServices.getPageByHandle(handle); + GBLog.info(`BASIC: Web Automation CLICK BUTTON: ${text} ${index}.`); + if (!index) { + index = 1; + } + const els = await page.$x(`//button[contains(.,'${text}')]`); + await els[index - 1].click(); + await this.debugStepWeb(pid, page); + } + /** * Returns the screenshot of page or element