new(basic.gblib): Command TEXT OF

This commit is contained in:
phpussente 2023-05-09 11:20:40 -03:00
parent b87a0c397c
commit a03a7c7ba0
2 changed files with 39 additions and 9 deletions

View file

@ -802,11 +802,20 @@ export class KeywordsExpressions {
keywords[i++] = [ keywords[i++] = [
/^\s*(click link text)(\s*)(.*)/gim, /^\s*(click link text)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {
const params = this.getParams('page,' + $3, ['text', 'index']); const params = this.getParams($3, ['text', 'index']);
return `await wa.linkByText ({pid: pid, handle: page, ${params}})`; return `await wa.linkByText ({pid: pid, handle: page, ${params}})`;
} }
]; ];
keywords[i++] = [
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*(text of)(\s*)(.*)/gim,
($0, $1, $2, $3, $4) => {
const params = this.getParams($4, ['frameOrSelector', 'selector']);
return `
${$1} = await wa.getTextOf ({pid: pid, handle: page, ${params}})`;
}
];
keywords[i++] = [ keywords[i++] = [
/^\s*(click button)(\s*)(.*)/gim, /^\s*(click button)(\s*)(.*)/gim,
($0, $1, $2, $3) => { ($0, $1, $2, $3) => {

View file

@ -103,8 +103,7 @@ export class WebAutomationServices {
// Try to find an existing handle. // Try to find an existing handle.
let session; let session;
if (handle) if (handle) {
{
session = GBServer.globals.webSessions[handle]; session = GBServer.globals.webSessions[handle];
} }
else if (sessionName) { else if (sessionName) {
@ -464,6 +463,28 @@ export class WebAutomationServices {
return null; return null;
}) })
); );
return results.find(Boolean); return results.find(Boolean);
} }
public async getTextOf({ pid, handle, frameOrSelector, selector }) {
const page = WebAutomationServices.getPageByHandle(handle);
GBLog.info(`BASIC: Web Automation CLICK element: ${frameOrSelector}.`);
if (frameOrSelector) {
const result = await page.$eval(
frameOrSelector,
(ul) => {
let items = "";
for (let i = 0; i < ul.children.length; i++) {
items = `${items}${ul.children[i].textContent}\n`;
}
return items;
}
)
await this.debugStepWeb(pid, page);
return result;
}
}
} }