简体   繁体   中英

How to type in Laravel Dusk with an array of input text?

I have these array of input text :

<input type="text" name="amount[0]">
<input type="text" name="amount[1]">
<input type="text" name="amount[2]">
<input type="text" name="amount[3]">

and I want to type a value using Laravel Dusk. I can't just hardcode using :

$browser->visit('/create')
    ->type('amount[0]', '100')
    ->type('amount[1]', '100')
    ->type('amount[2]', '100')
    ->type('amount[3]', '100');

because the number of input fields depends on the number of items in the database.

I tried using :

$browser->visit('/create')
    ->type('amount[]', '100');

but it doesn't work. Is there a way to achieve this?

You can find the inputs with a CSS selector:

$inputs = $browser->elements('input[name^="amount["]');

foreach ($inputs as $input) {
    $input->sendKeys('100');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM