david001's avatar

Dusk check/uncheck

Hi, I am not able to check the checkbox. My all checkbox ids are unique. I tried to loop and check but it didn't work for me. I also tried to check one by one based on id but did not work if i use this selector $browser->click('.custom-check-box'); it just check first one. Any help please

<div class="checkbox-group" data-parsley-group="step-0">
  <span class="checkbox custom-checkbox custom-check-box">
    <input
      id="field_9092_1634"
      data-parsley-multiple="field_9092"
      type="checkbox"
      value="1634"
      name="field_9092[]"
      data-parsley-group="step-0"
    /><label class="check-box-label" for="field_9092_1634">a</label></span
  ><span class="checkbox custom-checkbox custom-check-box"
    ><input
      id="field_9092_1635"
      data-parsley-multiple="field_9092"
      type="checkbox"
      value="1635"
      name="field_9092[]"
      checked=""
      data-parsley-group="step-0"
    /><label class="check-box-label" for="field_9092_1635">b</label></span


  ><span class="checkbox custom-checkbox custom-check-box"
    ><input
      id="field_9092_1636"
      data-parsley-multiple="field_9092"
      type="checkbox"
      value="1636"
      name="field_9092[]"
      data-parsley-group="step-0"
    /><label class="check-box-label" for="field_9092_1636">c</label></span
  >
  <div class="errorcontainer"></div>
</div>
0 likes
5 replies
bugsysha's avatar
foreach(range(1634, 1636) as $value) {
  $browser->click('input[value='.$value.']');
}

or

foreach(range(1634, 1636) as $value) {
  $browser->click('#field_9092_'.$value);
}

Bunch of ways to do it, just pick the one you like most.

david001's avatar

@bugsysha I tried in this way and it did not work

            $value2=2;
            $value3=3;
            $value1=1;
            $browser->click('#field_7_'.$value2);
            $browser->click('#field_7_'.$value3);
            $browser->click('#field_7_'.$value1);

my checkbox  has id as <input type="checkbox" id="field_7_1" value="1">
<input type="checkbox" id="field_7_2"  value="2">
<input type="checkbox" id="field_7_3"  value="3">
david001's avatar

i tried with check as well it didn't work . If i have a single checkbox in a view, $browser->check() works fine But I have three checkbox and I want to click all three checkbox and $browser->check() or $browser->click() is not working

bugsysha's avatar

Take screenshot at each check() before and/or after and see what is happening.

Please or to participate in this conversation.