set method
Implementation
Future<Online> set(AbstractSelector selector, Object? obj,
{Object? max = null,
bool show = true,
Duration? timeout = null,
int index = 0,
bool click = false}) async {
String text = obj?.toString() ?? '';
if (show) Show.set_value(selector.selector, text);
// first wait for the page to load and the selector to appear
if (selector is XPath) {
await (await page).waitForXPath(selector.selector);
} else {
await (await page).waitForSelector(selector.selector);
}
var selectedElements = await (await page).$$(selector.selector);
if (selectedElements.length > index) {
var selected = selectedElements[index];
if (click) {
await selected.click();
}
await selected.evaluateHandle('''(element, text) => {
if (element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement || element instanceof HTMLSelectElement) {
element.focus(); // Focus on the element
var inputEvent = new Event('input', {bubbles: true});
var changeEvent = new Event('change', {bubbles: true});
element.dispatchEvent(inputEvent);
element.value = text;
element.dispatchEvent(changeEvent);
element.blur(); // Remove focus from the element
}
}''', args: [text]);
}
return this;
}