Find an element by CSS selector or semantic options. Waits for element to exist.
(selector: string | SelectorOptions, options?: FindOptions)
| 622 | |
| 623 | /** Find an element by CSS selector or semantic options. Waits for element to exist. */ |
| 624 | find(selector: string | SelectorOptions, options?: FindOptions): FluentElement { |
| 625 | const promise = (async () => { |
| 626 | const params: Record<string, unknown> = { |
| 627 | context: this.contextId, |
| 628 | timeout: options?.timeout, |
| 629 | }; |
| 630 | |
| 631 | if (typeof selector === 'string') { |
| 632 | debug('page.find', { selector, timeout: options?.timeout }); |
| 633 | params.selector = selector; |
| 634 | } else { |
| 635 | debug('page.find', { ...selector, timeout: options?.timeout }); |
| 636 | Object.assign(params, selector); |
| 637 | if (selector.timeout && !options?.timeout) params.timeout = selector.timeout; |
| 638 | } |
| 639 | |
| 640 | const result = await this.client.send<VibiumFindResult>('vibium:page.find', params); |
| 641 | |
| 642 | const info: ElementInfo = { |
| 643 | tag: result.tag, |
| 644 | text: result.text, |
| 645 | box: result.box, |
| 646 | }; |
| 647 | |
| 648 | const selectorStr = typeof selector === 'string' ? selector : ''; |
| 649 | const selectorParams = typeof selector === 'string' ? { selector } : { ...selector }; |
| 650 | return new Element(this.client, this.contextId, selectorStr, info, undefined, selectorParams); |
| 651 | })(); |
| 652 | return fluent(promise); |
| 653 | } |
| 654 | |
| 655 | /** Find all elements matching a CSS selector or semantic options. Waits for at least one. */ |
| 656 | async findAll(selector: string | SelectorOptions, options?: FindOptions): Promise<Element[]> { |