Skip to content

Commit 10c7153

Browse files
oleg-andreyevOndraM
authored andcommitted
Add Safari workaround for detecting multi-select element
1 parent c2564bb commit 10c7153

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

lib/WebDriverSelect.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ public function __construct(WebDriverElement $element)
2626
}
2727
$this->element = $element;
2828
$value = $element->getAttribute('multiple');
29-
$this->isMulti = $value === 'true';
29+
30+
/**
31+
* There is a bug in safari webdriver that returns 'multiple' instead of 'true' which does not match the spec.
32+
* Apple Feedback #FB12760673
33+
*
34+
* @see https://www.w3.org/TR/webdriver2/#get-element-attribute
35+
*/
36+
$this->isMulti = $value === 'true' || $value === 'multiple';
3037
}
3138

3239
public function isMultiple()

tests/functional/WebDriverSelectTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ protected function setUp(): void
2020
$this->driver->get($this->getTestPageUrl(TestPage::FORM));
2121
}
2222

23-
public function testShouldCreateNewInstanceForSelectElementAndDetectIfItIsMultiple(): void
23+
/**
24+
* @dataProvider multipleSelectDataProvider
25+
*/
26+
public function testShouldCreateNewInstanceForSelectElementAndDetectIfItIsMultiple(string $selector): void
2427
{
2528
$originalElement = $this->driver->findElement(WebDriverBy::cssSelector('#select'));
26-
$originalMultipleElement = $this->driver->findElement(WebDriverBy::cssSelector('#select-multiple'));
29+
$originalMultipleElement = $this->driver->findElement(WebDriverBy::cssSelector($selector));
2730

2831
$select = new WebDriverSelect($originalElement);
2932
$selectMultiple = new WebDriverSelect($originalMultipleElement);
@@ -35,6 +38,15 @@ public function testShouldCreateNewInstanceForSelectElementAndDetectIfItIsMultip
3538
$this->assertTrue($selectMultiple->isMultiple());
3639
}
3740

41+
public static function multipleSelectDataProvider(): array
42+
{
43+
return [
44+
['#select-multiple'],
45+
['#select-multiple-2'],
46+
['#select-multiple-3'],
47+
];
48+
}
49+
3850
public function testShouldThrowExceptionWhenNotInstantiatedOnSelectElement(): void
3951
{
4052
$notSelectElement = $this->driver->findElement(WebDriverBy::cssSelector('textarea'));

tests/functional/web/form.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@
4848
<option value="fourth">Fourth with spaces inside</option>
4949
<option value="fifth"> Fifth surrounded by spaces </option>
5050
</select>
51+
<label for="select-multiple-2"></label>
52+
<select name="select-multiple-2" id="select-multiple-2" multiple="multiple">
53+
<option value="first">First</option>
54+
<option value="second">This is second option</option>
55+
<option value="third">This is not second option</option>
56+
<option value="fourth">Fourth with spaces inside</option>
57+
<option value="fifth"> Fifth surrounded by spaces </option>
58+
</select>
59+
<label for="select-multiple-3"></label>
60+
<select name="select-multiple-3" id="select-multiple-3" multiple="">
61+
<option value="first">First</option>
62+
<option value="second">This is second option</option>
63+
<option value="third">This is not second option</option>
64+
<option value="fourth">Fourth with spaces inside</option>
65+
<option value="fifth"> Fifth surrounded by spaces </option>
66+
</select>
5167
<br>
5268

5369
<fieldset>

0 commit comments

Comments
 (0)