Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Apple Safari 11.x cannot toggle selection of options in <select multiple> #24

@craigfowler

Description

@craigfowler

Beware - much of the investigation in this ticket is incorrect. This problem is not specific to select elements with the multiple attribute.

Safari versions 11.0 (and presumably upwards) will not correctly select/deselect single options within an HTML <select multiple> with just a click. As far as I am aware, a modifier key (presumably command) needs to be held down as part of the click.

This is currently impossible to test or fix though, because the command key is not accepted as a modifier key by the Selenium actions service.

Code example

The code to fix this should be as follows, however this fails with an exception raised by Selenium WebDriver, because Keys.Command is not accepted as a modifier key.

string modifierKey = Keys.Command;
IWebDriver driver;
IWebElement option;

new OpenQA.Selenium.Interactions.Actions(driver)
  .KeyDown(modifierKey)
  .Click(option)
  .KeyUp(modifierKey)
  .Perform();

Exception raised

When attempting the code above however, an exception is raised which prevents this from being tested:

1) Error : CSF.Screenplay.Selenium.Tests.Actions.DeselectTests.DeselectAll_leaves_nothing_selected(CSF.Screenplay.Actors.Cast,Value is not created.)
System.ArgumentException : key must be a modifier key (Keys.Shift, Keys.Control, or Keys.Alt)
Parameter name: key
  at OpenQA.Selenium.Interactions.Internal.SingleKeyAction..ctor (OpenQA.Selenium.IKeyboard keyboard, OpenQA.Selenium.IMouse mouse, OpenQA.Selenium.ILocatable actionTarget, System.String key) [0x0001a] in <ffa85d3056554eccb394847e2c433dfa>:0 
  at OpenQA.Selenium.Interactions.KeyDownAction..ctor (OpenQA.Selenium.IKeyboard keyboard, OpenQA.Selenium.IMouse mouse, OpenQA.Selenium.ILocatable actionTarget, System.String key) [0x00000] in <ffa85d3056554eccb394847e2c433dfa>:0 
  at OpenQA.Selenium.Interactions.Actions.KeyDown (OpenQA.Selenium.IWebElement element, System.String theKey) [0x00022] in <ffa85d3056554eccb394847e2c433dfa>:0 
  at OpenQA.Selenium.Interactions.Actions.KeyDown (System.String theKey) [0x00000] in <ffa85d3056554eccb394847e2c433dfa>:0 
  at CSF.Selenium.Support.UI.SelectElementUsingModifierKey.ToggleSelectedState (OpenQA.Selenium.IWebElement option) [0x00024] in <d02bd3bbfb964cf9ace647527e16f14c>:0 
  at CSF.Selenium.Support.UI.SelectElement.SetSelected (OpenQA.Selenium.IWebElement option, System.Boolean select) [0x00035] in <d02bd3bbfb964cf9ace647527e16f14c>:0 
  at CSF.Selenium.Support.UI.SelectElement.DeselectAll () [0x00031] in <d02bd3bbfb964cf9ace647527e16f14c>:0 
  at CSF.Screenplay.Selenium.Actions.DeselectAll.PerformAs (CSF.Screenplay.Actors.IPerformer actor, CSF.Screenplay.Selenium.Abilities.BrowseTheWeb ability, CSF.Screenplay.Selenium.Models.IWebElementAdapter element, CSF.Selenium.Support.UI.SelectElement select) [0x00001] in <d02bd3bbfb964cf9ace647527e16f14c>:0 
  at CSF.Screenplay.Selenium.Actions.SelectActionDriver.PerformAs (CSF.Screenplay.Actors.IPerformer actor, CSF.Screenplay.Selenium.Abilities.BrowseTheWeb ability, CSF.Screenplay.Selenium.Models.IWebElementAdapter element) [0x0000a] in <d02bd3bbfb964cf9ace647527e16f14c>:0 
  at CSF.Screenplay.Selenium.Actions.TargettedAction.PerformAs (CSF.Screenplay.Actors.IPerformer actor) [0x00011] in <d02bd3bbfb964cf9ace647527e16f14c>:0 
  at CSF.Screenplay.Performables.Performable.CSF.Screenplay.Performables.IPerformable.PerformAs (CSF.Screenplay.Actors.IPerformer actor) [0x0000e] in <65c017afcc0a456da82fc37802bd2e37>:0 
  at CSF.Screenplay.Actors.Actor.Perform (CSF.Screenplay.Performables.IPerformable performable) [0x0002f] in <65c017afcc0a456da82fc37802bd2e37>:0 
  at CSF.Screenplay.Actors.Actor.CSF.Screenplay.Actors.IWhenActor.AttemptsTo (CSF.Screenplay.Performables.IPerformable performable) [0x00006] in <65c017afcc0a456da82fc37802bd2e37>:0 
  at CSF.Screenplay.Selenium.Tests.Actions.DeselectTests.DeselectAll_leaves_nothing_selected (CSF.Screenplay.Actors.ICast cast, System.Lazy`1[T] webBrowserFactory) [0x0002a] in <a496b20939474109b922e54b647363e8>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <2e7c1c96edae44d496118948ca617c11>:0 

Impact

Because of the upstream exception, I cannot currently send (what I believe to be) the correct modifier key for toggling selection of a single option for Safari 11. This means that tests where the appropriate browser flag is present (requires command click to toggle selection) have had to be ignored for now. It also means I cannot fully support Safari 11+.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions