Find a DOM element on the page by CSS selector
import { openBrowser, openTab, findElement } from 'puppet-strings'
async function run() {
const browser = await openBrowser('google-chrome')
const tab = await openTab(browser, 'https://www.npmjs.com/')
const header = await findElement(tab, '#pane-homepage-hero h1')
const blogLink = await findElement(tab, 'footer a', 'Blog')
}
run()
tab
(Tab)selector
(string): A CSS selector to search fortext
(string?): Optional text content to search foroptions = {}
(object)timeout = 5000
(number): How long to search for a match
element
(Promise)
findElement
searches the page and all its iframe
s for a default of 5
seconds, returning the first element that matches the CSS selector
and
contains the text
(if provided) or throwing an exception if none are found.
The object returned will contain as properties the innerText
, outerHTML
, and
attributes
of the element.