Shivam
Shivam

Reputation: 113

How to change value of input with same name using Puppeteer?

So there is a form in which input are like this

<input class="input _ngcontent-EXCHANGE-32" focusableelement="" aria-invalid="false" aria-labelledby="930C5093-F4DD-4A01-BD2E-96F2873C8559--0" aria-disabled="false" tabindex="0" type="money64">

So there are two inputs like the above. I want to change value of first input to X and second input to Y.

await page.$eval('input[type=money64]', el => el.value = 'X');
await page.$eval('input[type=money64]', el => el.value = 'Y');

The above code changes the value of the same input first to X then to Y and the second input remains the same. So how can I set the value of second input type = money64 using puppeteer.

Upvotes: 0

Views: 2074

Answers (1)

Aman Gupta
Aman Gupta

Reputation: 1874

<div id="abc">
    <input class="custom1" type="text" >
    <input class="custom2" type="text">
</div>


 let firstInput = Array.from(document.querySelectorAll('#abc input:nth-child(1)'));
// change content for the firstInput
// repeat the same for the second child

Try this.

You can also try:

await page.$eval('#abc input:nth-child(1)', el => el.value = 'X');
await page.$eval('#abc input:nth-child(2)', el => el.value = 'Y');

Check this.

Upvotes: 2

Related Questions