/* * HTML parsing and access. * https://docs.k6.io/docs/k6html */ // === Main === // ------------ /** * Parse an HTML string. * @param html - HTML source. * @returns Document node object. * @public */ export function parseHTML(html: string): Selection; // === Selection === // ----------------- /** * Represents a set of nodes in a DOM tree. * https://docs.k6.io/docs/selection-k6html * @public */ export abstract class Selection { protected __brand: never; /** * Get the value of an attribute for the first element in the Selection. * https://docs.k6.io/docs/selectionattrname * @param name - Name of attribute to get. * @returns Attribute value. */ attr(name: string): string | undefined; /** * Get the children of each element in the set of matched elements, * optionally filtered by a selector. * https://docs.k6.io/docs/selectionchildrenselector * @param selector - Selector expression. * @returns Selected children. */ children(selector?: string): Selection; /** * For each element in the set, get the first element that matches the * selector by testing the element itself and traversing up through its * ancestors in the DOM tree. * https://docs.k6.io/docs/selectionclosestselector * @param selector - Selector expression. * @returns Selected nodes. */ closest(selector: string): Selection; /** * Get the children of each element in the set of matched elements, * including text and comment nodes. * https://docs.k6.io/docs/selectioncontents * @returns Selected nodes. */ contents(): Selection; /** * Return the value at the named data store for the first element in the * set of matched elements. * https://docs.k6.io/docs/selectiondatakey * @param key - A string naming the piece of data to set.\ * @returns The value at the named data store. */ data(key?: string): string | undefined; /** * Iterate over a Selection (k6/html), executing a function for each * matched element. * https://docs.k6.io/docs/selectioneachfn * @param handler - Logic to execute for each element. */ each(handler: Handler): void; /** * Reduce the set of matched elements to the one at the specified index. * https://docs.k6.io/docs/selectioneqindex * @param index - An integer indicating the 0-based position of the element. * @returns Unary set of selected element. */ eq(index: number): Selection; /** * Reduce the set of matched elements to those that match the selector * or pass the function's test. * https://docs.k6.io/docs/selectionfilterfn * @param selector - Selector expression. * @returns Selected elements. */ filter(selector: string): Selection; // tslint:disable:unified-signatures /** * Reduce the set of matched elements to those that match the selector * or pass the function's test. * https://docs.k6.io/docs/selectionfilterfn * @param selector - A function used as a test for each element in the set. * @returns Selected elements. */ filter(selector: Tester): Selection; // tslint:disable:unified-signatures /** * Reduce the set of matched elements to those that match the selector * or pass the function's test. * https://docs.k6.io/docs/selectionfilterfn * @param selector - A selection to match elements against. * @returns Selected elements. */ filter(selector: Selection): Selection; // tslint:disable:unified-signatures /** * Find the selection descendants, filtered by a selector. * https://docs.k6.io/docs/selectionfindselector * @param selector - Selector expression. * @returns Selected elements. */ find(selector: string): Selection; /** * Reduce the set of matched elements to the first. * https://docs.k6.io/docs/selectionfirst * @returns Unary set of first element. */ first(): Selection; /** * Retrieve the element matched by the selector. * https://docs.k6.io/docs/selectiongetindex * @param index - A zero-based integer indicating which element to retrieve. * @returns Selected element. */ get(index: number): Element; /** * Reduce the set of matched elements to those that have a descendant that * matches the selector. * https://docs.k6.io/docs/selectionhasselector * @param selector - Selector expression. * @returns Selected elements. */ has(selector: string): Selection; /** * Get the HTML contents of the first element. * https://docs.k6.io/docs/selectionhtml * @returns The HTML content of the first element. */ html(): string | undefined; /** * Check the current matched set of elements against a selector or element * and return true if at least one of these elements matches the given * arguments. * https://docs.k6.io/docs/selectionisselector * @param selector - Selector expression. * @returns Whether selector matched at least one element. */ is(selector: string): boolean; // tslint:disable:unified-signatures /** * Check the current matched set of elements against a selector or element * and return true if at least one of these elements matches the given * arguments. * https://docs.k6.io/docs/selectionisselector * @param selector - A function used as a test for each element in the set. * @returns Whether selector matched at least one element. */ is(selector: Tester): boolean; // tslint:disable:unified-signatures /** * Check the current matched set of elements against a selector or element * and return true if at least one of these elements matches the given * arguments. * https://docs.k6.io/docs/selectionisselector * @param selector - A selection to match against. * @returns Whether selector matched at least one element. */ is(selector: Selection): boolean; // tslint:disable:unified-signatures /** * Reduce the set of matched elements to the final one. * https://docs.k6.io/docs/selectionlast * @returns Unary set of last element. */ last(): Selection; /** * Pass each element in the current matched set through a function, * producing a new Array containing the return values. * https://docs.k6.io/docs/selectionmapfn * @param mapper - Procedure to execute on each element. * @returns Mapper return values. */ map(mapper: Mapper): unknown[]; /** * Get the immediately following sibling of each element. * https://docs.k6.io/docs/selectionnext * @param selector - Selector expression. * @returns Selected elements. */ next(selector?: string): Selection; /** * Get all following siblings of each element, * optionally filtered by a selector. * https://docs.k6.io/docs/selectionnextallselector * @param selector - Selector expression. * @returns Selected elements. */ nextAll(selector?: string): Selection; /** * Get all following siblings of each element up to but not including the * element matched by the selector. * https://docs.k6.io/docs/selectionnextuntilselector * @param selector - Selector expression. * @returns Selected elements. */ nextUntil(selector?: string): Selection; /** * Remove elements. * https://docs.k6.io/docs/selectionnotselector * @param selector - Selector expression. * @returns Selection with matched elements removed. */ not(selector: string): Selection; // tslint:disable:unified-signatures /** * Remove elements. * https://docs.k6.io/docs/selectionnotselector * @param selector - A function used as a test for each element in the set. * @returns Selection with matched elements removed. */ not(selector: Tester): Selection; // tslint:disable:unified-signatures /** * Get the parent of each element, optionally filtered by a selector. * https://docs.k6.io/docs/selectionparentselector * @param selector - Selector expression. * @returns Selected elements. */ parent(selector?: string): Selection; /** * Get the ancestors of each element, optionally filtered by a selector. * https://docs.k6.io/docs/selectionparentsselector * @param selector - Selector expression. * @returns Selected elements. */ parents(selector?: string): Selection; /** * Get the ancestors of each element, * up to but not including the element matched by the selector. * https://docs.k6.io/docs/selectionparentsuntilselector * @param selector - Selector expression. * @returns Selected elements. */ parentsUntil(selector?: string): Selection; /** * Get the immediately preceding sibling of each element. * https://docs.k6.io/docs/selectionprevselector * @param selector - Selector expression. * @returns Selected elements. */ prev(selector?: string): Selection; /** * Get all preceding siblings of each element, * optionally filtered by a selector. * https://docs.k6.io/docs/selectionprevallselector * @param selector - Selector expression. * @returns Selected elements. */ prevAll(selector?: string): Selection; /** * Get all preceding siblings of each element * up to but not including the element matched by the selector. * https://docs.k6.io/docs/selectionprevuntilselector * @param selector - Selector expression. * @returns Selected elements. */ prevUntil(selector?: string): Selection; /** * Encode a set of form elements as a string * in standard URL-encoded notation for submission. * https://docs.k6.io/docs/selectionserialize * @returns URL-encoded representation of the form or form elements. */ serialize(): string; /** * Encode a set of form elements as an array of name-value objects. * `[{ name: "name", value: "value" }, ... ]` * https://docs.k6.io/docs/selectionserializearray * @returns Array of name value objects of the form or form elements. */ serializeArray(): FormValue[]; /** * Encode a set of form elements as an object. * `{ inputName: "value", checkboxName: "value", ... }` * https://docs.k6.io/docs/selectionserializeobject * @returns Object representation of the form or form elements, * key is field name and value is field value. */ serializeObject(): { [name: string]: string }; /** * Return the number of elements in the selection. * https://docs.k6.io/docs/selectionsize * @returns The number of elements in the selection. */ size(): number; /** * Reduce the set of elements to a subset specified by a range of indices. * https://docs.k6.io/docs/selectionslicestart-end * @param start - An integer indicating the 0-based position at which the * elements begin to be selected. * @param end - An integer indicating the 0-based position at which the * elements stop being selected. * @returns Selected elements. */ slice(start: number, end?: number): Selection; /** * Get the text content of the selection. * @returns Text content. */ text(): string; /** * Retrieve all the elements contained in the selection as an array. * https://docs.k6.io/docs/selectiontoarray * @returns A unary selection of each element. */ toArray(): Selection[]; /** * Get the current value of the first element. * @returns The value of the first element. */ val(): string | undefined; } /** * Form field value. * @public */ export interface FormValue { /** Field name. */ name: string; /** Field value. */ value: string; } /** * Test procedure. * @public */ export interface Tester { /** * @param index - Current index. * @param element - Current element. * @returns Whether element passes test. */ (index: number, element: Element): boolean; } /** * Handle procedure. * @public */ export interface Handler { /** * @param index - Current index. * @param element - Current element. */ (index: number, element: Element): void; } /** * Map procedure. * @public */ export interface Mapper { /** * @param index - Current index. * @param element - Current element. * @returns Value element maps to. */ (index: number, element: Element): unknown; } // === Attribute === // ----------------- /** * HTML attribute. * @public */ export abstract class Attribute { protected __brand: never; /** Name. */ name: string; /** Owning element. */ ownerElement: Element; /** Value. */ value: string; /** Local part of qualified name. */ localName(): string; /** Namespace URI. */ namespaceURI(): string; /** Namespace prefix. */ prefix(): string; } // === Node type === // ----------------- /** * Node type. * @public */ export enum NodeType { ElementNode = 1, TextNode = 3, CommentNode = 8, DocumentNode = 9, DoctypeNode = 10, } // === Element === // --------------- /** * HTML node. * https://docs.k6.io/docs/element-k6html * @public */ export abstract class Element { protected __brand: never; /** Dictionary of element attributes. */ attributes(): { [name: string]: Attribute }; /** Count of child elements. */ childElementCount(): number; /** Child nodes. */ childNodes(): Element[]; /** Child elements. */ children(): Element[]; /** Class names. */ classList(): string[]; /** * Class value. * @returns Single string with all class names. */ className(): string | undefined; /** * Check whether contains element. * @param element - Possibly contained element. * @returns Whether contains element. Self containment returns `true`. */ contains(element: Element): boolean; /** First child node. */ firstChild(): Element | undefined; /** First child element. */ firstElementChild(): Element | undefined; /** * Get attribute value. * @param name - Attribute name. * @returns Attribute value. */ getAttribute(name: string): string | undefined; /** * Get attribute node. * @param name - Attribute name. * @returns Attribute node. */ getAttributeNode(name: string): Attribute | undefined; /** * Get descendant elements in class. * @param name - Class name. * @return Descendant elements in class. */ getElementsByClassName(name: string): Element[]; /** * Get descendant elements with tag name. * @param name - Tag name. * @return Descendant elements with tag name. */ getElementsByTagName(name: string): Element[]; /** * Check whether has attribute. * @param name - Attribute name. * @returns Whether has attribute. */ hasAttribute(name: string): boolean; /** Whether has any attributes. */ hasAttributes(): boolean; /** Whether has any child nodes. */ hasChildNodes(): boolean; /** Identifier value. */ id(): string; /** Inner HTML. Markup of content. */ innerHTML(): string | undefined; /** Whether has the default namespace. */ isDefaultNamespace(): boolean; /** * Check whether node is equal. * @param node - Node to check. * @returns Whether node has equal HTML representation. */ isEqualNode(node: Element): boolean; /** * Check whether node is identical. * @param node - Node to check. * @returns Whether node is self. */ isSameNode(node: Element): boolean; /** Value of `lang` attribute. */ lang(): string | undefined; /** Last child node. */ lastChild(): Element | undefined; /** Last child element. */ lastElementChild(): Element | undefined; /** * Check whether matches selector. * @param selector - Selector expression. * @returns Whether matches selector. */ matches(selector: string): boolean; /** Namespace URI. */ namespaceURI(): string; /** Next sibling element. */ nextElementSibling(): Element | undefined; /** Next sibling node. */ nextSibling(): Element | undefined; /** Node name. */ nodeName(): string; /** Node type. */ nodeType(): NodeType | undefined; /** Node value. */ nodeValue(): string | undefined; /** Owning document node. */ ownerDocument(): Element | undefined; /** Parent element. */ parentElement(): Element | undefined; /** Parent node. */ parentNode(): Element | undefined; /** Previous sibling element. */ previousElementSibling(): Element | undefined; /** Previous sibling node. */ previousSibling(): Element | undefined; /** * Select a single descendant element. * @param selector - Selector expression. * @returns First matched element. */ querySelector(selector: string): Element | undefined; /** * Select descendant elements. * @param selector - Selector expression. * @returns All matched elements. */ querySelectorAll(selector: string): Element[]; /** Text content. */ textContent(): string; /** String representation, eg `[object html.Node]`. */ toString(): string; } /** * HTML element. * https://docs.k6.io/docs/element-k6html * @public */ export abstract class AnchorElement extends HrefElement { protected __brand: never; } /** * HTML element. * https://docs.k6.io/docs/element-k6html * @public */ export abstract class AreaElement extends HrefElement { protected __brand: never; } /** * HTML