minkphp / minkphp/Mink

How do deselect a particular SELECT option in a multi-select

Open
#374 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
PHP
Stars
1.6k
Forks
286
PR merge metrics
No merged PRs in 30d

Description

In Selenium individual options can be easily selected/deselect by clicking on them (even if SELECT itself isn't expanded). It even doesn't force you to do a Ctrl/CMD+Click on an option to append it to current selection. I haven't seen such luxury in other JavaScript enabled drivers (e.g. Sahi, Zombie), where the only method that allows to manipulate SELECT element is called setSelected (or similar) and accepts an array of option values to be selected.

Without individual option deselection the only possible way is to call NodeElement::selectOption method multiple times in following fashion:

$multi_select->selectOption('value1', true); // true - to reset selection to this option
$multi_select->selectOption('value2', false); // false - to append to current selection
$multi_select->selectOption('valueN', false); // false - to append to current selection
...

Having some sort of resetSelection method of a driver, that would uncheck all options would be a great help in this case.
Implementing such method however isn't that easy as it sounds, because native setSelected methods of underlying browser controllers:

  1. doesn't support selecting non-existing options just to unselect all of them
  2. doesn't support setValue('') call on a multi-select just to unselect all options

Without changing DriverInterface and associated drivers I don't have any other choice for deselection an option, then:

  1. use getValue to get currently selected options
  2. remove options, that needs to be deselected from resulting array
  3. call selectOption multiple times (see example in the beginning)

This approach has major drawback - multiple onchange event calls, that doesn't really happen when user himself is changing multi-select selection.

Any ideas would be appreciated.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading NodeElement::selectOption, DriverInterface, and the associated drivers, then trace how getValue and selectOption handle multi-select values. The requested outcome is a way to deselect particular options without repeatedly triggering onchange events; the issue does not name a test file or settle the API design.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.