I made a workaround on this.
/**
* Select the given value or random value of a drop-down field.
*
* @param string $field
* @param $browser
* @param array|null $values
* @return $this
* @internal param string $value
*/
public function selectMultiple($field, $browser, $values = [])
{
$element = $browser->resolver->resolveForSelection($field);
$options = $element->findElements(WebDriverBy::tagName('option'));
if (empty($values)) {
$maxSelectValues = sizeof($options) - 1;
$minSelectValues = rand(0, $maxSelectValues);
foreach (range($minSelectValues, $maxSelectValues) as $optValue) {
$options[$optValue]->click();
}
} else {
foreach ($options as $option) {
$optValue = (string)$option->getAttribute('value');
if (in_array($optValue, $values)) {
$option->click();
}
}
}
return $this;
}
Then you will call the function like this.
$this->browse(function (Browser $browser) {
$this->selectMultiple("field_name[]", $browser)
}
Or you might do this if don't want to randomized the selected values
$this->browse(function (Browser $browser) {
$this->selectMultiple("field_name[]", $browser, ["value1", "value2"])
}
I hope it helps.