Home > front end >  puppeteer: How to set Value for a Input Element for REACT and Typescript
puppeteer: How to set Value for a Input Element for REACT and Typescript

Time:09-24

I would like to test my app with Puppeteer. I used REACT and TypeScript. how can I set the input correctly? Please see the 2 attachments.

enter image description here enter image description here

I try the following, but without success:

1.try:

await page.waitForSelector('#MuiButtonBase-root');
// await page.select('#MuiTouchRipple-root');
await page.waitForSelector('#name');
await page.type('#name', 'Hello');

2.try:

await page.$eval('#MuiDialogContent-root input:MuiFormControl-root:nth-child(1)', el => el.value = 'Hello');  

CodePudding user response:

That's the wrong selector. #name is the same as [id="name"] and you want [name="name"]

Use the 1st way for React or the onChange won't get triggered.

  • Related