playwright#ElementHandle TypeScript Examples
The following examples show how to use
playwright#ElementHandle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: are-options-already-selected-in-handle.ts From playwright-fluent with MIT License | 6 votes |
export async function areOptionsAlreadySelectedInHandle(
selector: ElementHandle<Element> | null | undefined,
name: string,
expectedOptionLabels: string[],
): Promise<boolean> {
if (expectedOptionLabels.length === 0) {
throw new Error(`You must specify at least one option for selector '${name}'`);
}
const allOptions = await getAllOptionsOfHandle(selector, name);
const result = expectedOptionLabels.every((expectedLabel) =>
allOptions
.filter((option) => option.selected)
.some((selectedOption) => selectedOption.label === expectedLabel),
);
return result;
}
Example #2
Source File: functions.ts From actor-facebook-scraper with Apache License 2.0 | 6 votes |
evaluateFilterMap = async <E extends Element, C extends (el: E) => Promise<any>>(els: ElementHandle<E>[], map: C) => {
type MapReturn = NonNullable<C extends (...args: any) => PromiseLike<infer R> ? R : any>;
const values: MapReturn[] = [];
for (const el of els) {
try {
const result = await el.evaluate(map);
if (result !== undefined && result !== null) {
values.push(result as unknown as MapReturn);
}
} catch (e) {
// suppress errors, show them on debug
log.debug(e.message, { values });
}
}
return values;
}
Example #3
Source File: bpmn-page-utils.ts From bpmn-visualization-js with Apache License 2.0 | 6 votes |
async getContainerCenter(): Promise<Point> {
const containerElement: ElementHandle<SVGElement | HTMLElement> = await this.page.waitForSelector(`#${this.bpmnContainerId}`);
const rect = await containerElement.boundingBox();
return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };
}
Example #4
Source File: check-handle.ts From playwright-fluent with MIT License | 5 votes |
export async function checkHandle(
selector: ElementHandle<Element> | undefined | null,
name: string,
page: Page | Frame | undefined,
options: CheckOptions,
): Promise<void> {
if (!page) {
throw new Error(`Cannot check '${name}' because no browser has been launched`);
}
if (!selector) {
throw new Error(`Cannot check '${name}' because selector was not found in DOM`);
}
const hoverOptions: HoverOptions = {
...defaultHoverOptions,
verbose: options.verbose,
stabilityInMilliseconds: options.stabilityInMilliseconds,
timeoutInMilliseconds: options.timeoutInMilliseconds,
};
await hoverOnHandle(selector, name, page, hoverOptions);
report('Checking if selector is already checked ...', options.verbose);
const isChecked = await isHandleChecked(selector, { verbose: options.verbose });
if (isChecked) {
report('Selector is already checked: nothing to do.', options.verbose);
return;
}
report('waiting for the selector to be enabled ...', options.verbose);
await waitUntil(
() => isHandleEnabled(selector, { verbose: false }),
`Cannot check '${name}' because this selector is disabled`,
{
...options,
throwOnTimeout: true,
wrapPredicateExecutionInsideTryCatch: true,
},
);
await selector.check();
}