Merge pull request #276 from getmaxun/handle-inputs
feat: handle datetime-local `<input>` tag
This commit is contained in:
@@ -260,6 +260,16 @@ const onTimeSelection = async (data: { selector: string, value: string }) => {
|
||||
await handleWrapper(handleTimeSelection, data);
|
||||
}
|
||||
|
||||
const handleDateTimeLocalSelection = async (generator: WorkflowGenerator, page: Page, data: { selector: string, value: string }) => {
|
||||
await generator.onDateTimeLocalSelection(page, data);
|
||||
logger.log('debug', `DateTime Local value ${data.value} selected`);
|
||||
}
|
||||
|
||||
const onDateTimeLocalSelection = async (data: { selector: string, value: string }) => {
|
||||
logger.log('debug', 'Handling datetime-local selection event emitted from client');
|
||||
await handleWrapper(handleDateTimeLocalSelection, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper function for handling the keyup event.
|
||||
* @param keyboardInput - the keyboard input of the keyup event
|
||||
@@ -418,6 +428,7 @@ const registerInputHandlers = (socket: Socket) => {
|
||||
socket.on("input:date", onDateSelection);
|
||||
socket.on("input:dropdown", onDropdownSelection);
|
||||
socket.on("input:time", onTimeSelection);
|
||||
socket.on("input:datetime-local", onDateTimeLocalSelection);
|
||||
socket.on("action", onGenerateAction);
|
||||
};
|
||||
|
||||
|
||||
@@ -315,6 +315,26 @@ export class WorkflowGenerator {
|
||||
await this.addPairToWorkflowAndNotifyClient(pair, page);
|
||||
};
|
||||
|
||||
public onDateTimeLocalSelection = async (page: Page, data: { selector: string, value: string }) => {
|
||||
const { selector, value } = data;
|
||||
|
||||
try {
|
||||
await page.fill(selector, value);
|
||||
} catch (error) {
|
||||
console.error("Failed to fill datetime-local value:", error);
|
||||
}
|
||||
|
||||
const pair: WhereWhatPair = {
|
||||
where: { url: this.getBestUrl(page.url()) },
|
||||
what: [{
|
||||
action: 'fill',
|
||||
args: [selector, value],
|
||||
}],
|
||||
};
|
||||
|
||||
await this.addPairToWorkflowAndNotifyClient(pair, page);
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates a pair for the click event.
|
||||
* @param coordinates The coordinates of the click event.
|
||||
@@ -390,6 +410,16 @@ export class WorkflowGenerator {
|
||||
return;
|
||||
}
|
||||
|
||||
const isDateTimeLocal = elementInfo?.tagName === 'INPUT' && elementInfo?.attributes?.type === 'datetime-local';
|
||||
|
||||
if (isDateTimeLocal) {
|
||||
this.socket.emit('showDateTimePicker', {
|
||||
coordinates,
|
||||
selector
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
//const element = await getElementMouseIsOver(page, coordinates);
|
||||
//logger.log('debug', `Element: ${JSON.stringify(element, null, 2)}`);
|
||||
if (selector) {
|
||||
|
||||
Reference in New Issue
Block a user