phpunit-selenium icon indicating copy to clipboard operation
phpunit-selenium copied to clipboard

Selecting multiple <option> from a <select multiple>

Open ctrlaltca opened this issue 9 years ago • 4 comments

I have some old tests ported from SeleniumTestCase to Selenium2TestCase (btw, here's a small class i've created to make the porting easier: https://github.com/pradosoft/prado/blob/master/tests/test_tools/PradoGenericSelenium2Test.php ). In the old tests i used addSelection() in order to select an <option> in a <select multiple> element without deselecting the currently selected items. Such method doesn't exists in Selenium2TestCase, and googling around i saw that the current way to do this is something like:

keyPress(CONTROL);
element->click();
keyRelease(CONTROL);

If i'm not mistaken, in Selenium2TestCase no such keyPress/KeyRelease method exists, too. So, is there a way to accomplish what i'm trying to do?

ctrlaltca avatar Dec 07 '15 16:12 ctrlaltca

This may be useful: https://github.com/giorgiosironi/phpunit-selenium/blob/master/PHPUnit/Extensions/Selenium2TestCase.php#L89

giorgiosironi avatar Dec 08 '15 11:12 giorgiosironi

I've tried using keys() to send CONTROL and COMMAND before calling click(), but it doesn't seems to work; i suppose the key gets released before the click starts.

ctrlaltca avatar Dec 09 '15 07:12 ctrlaltca

I have also getting same issue. I have to select multiple div elements via pressing ctrl key + click !

@giorgiosironi Is there any specific function that can press and release key !

K-Deep avatar Apr 14 '16 10:04 K-Deep

In theory some keys are considered sticky, so they should remain pressed by default. Look for /session/:sessionId/element/:id/value and /session/:sessionId/keys at https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol

giorgiosironi avatar Apr 14 '16 12:04 giorgiosironi