SC
Size: a a a
SC
SC
VB
B
SC
SC
async innerHtml(): Promise<string> {
const element = await this.getElement();
return page.evaluate((el) => el.innerHTML, element);
}SC
AP
const text = await page.evaluate(element => element.textContent, element);?
SC
AP
SC
OK
OK
SC
OI
OI
SC
OI
OI
import { Page } from 'puppeteer';
import { forceElement } from '../utils/force';
import pFilter = require('p-filter');
export class DropDown {
private readonly page: Page;
private readonly rootSelector;
constructor(page, selector) {
this.page = page;
this.rootSelector = selector;
}
async selectByOptionText(option: string): Promise<void> {
const dropdown = await forceElement(this.page, this.rootSelector);
const value = await this.getValueBy(option);
await dropdown.select(value);
}
private async getValueBy(optionText: string): Promise<string> {
const options = await this.page.$$(`${this.rootSelector} option`);
const filtered = await pFilter(
options,
async (option) => {
const text = await this.page.evaluate((node: Element) => node.textContent, option);
return text === optionText;
});
if (filtered.length > 1) {
throw new Error('');
}
const element = filtered[0];
return (await element.getProperty('value')).jsonValue() as unknown as string;
}
}OI