Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use XPath expressions instead of CSS selectors on page.type in Puppeteer?

The code now:

await page.type('#filterdataTable > div.widget > input', "1234");

Can I use XPath instead of this CSS Selector?

like image 703
Hyperion Avatar asked Jan 28 '23 11:01

Hyperion


1 Answers

You can use page.$x() to obtain the ElementHandle of the element you want to select.

Then you can use elementHandle.type() to type text into the input field.

const example = await page.$x('//*[@id="filterdataTable"]/div[contains(concat(" ", normalize-space(@class), " "), " widget ")]/input');
await example[0].type('1234');
like image 58
Grant Miller Avatar answered Jan 30 '23 00:01

Grant Miller