Skip to content

Commit 3e9e7cb

Browse files
committed
InnerBrowser: selectOption can match by text when option has no value attribute #5547
1 parent d43fc9d commit 3e9e7cb

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/Codeception/Lib/InnerBrowser.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,13 +1122,16 @@ protected function matchOption(Crawler $field, $option)
11221122
}
11231123
$options = $field->filterXPath(sprintf('//option[text()=normalize-space("%s")]|//input[@type="radio" and @value=normalize-space("%s")]', $option, $option));
11241124
if ($options->count()) {
1125-
if ($options->getNode(0)->tagName === 'option') {
1126-
$options->getNode(0)->setAttribute('selected', 'selected');
1125+
$firstMatchingDomNode = $options->getNode(0);
1126+
if ($firstMatchingDomNode->tagName === 'option') {
1127+
$firstMatchingDomNode->setAttribute('selected', 'selected');
11271128
} else {
1128-
$options->getNode(0)->setAttribute('checked', 'checked');
1129+
$firstMatchingDomNode->setAttribute('checked', 'checked');
11291130
}
1130-
if ($options->first()->attr('value') !== false) {
1131-
return $options->first()->attr('value');
1131+
$valueAttribute = $options->first()->attr('value');
1132+
//attr() returns null when option has no value attribute
1133+
if ($valueAttribute !== null) {
1134+
return $valueAttribute;
11321135
}
11331136
return $options->first()->text();
11341137
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html>
2+
<body>
3+
<form action="/form/complex" method="POST">
4+
<select id="_payment_type" name="payment_type" required="" class="form-control">
5+
<option>За показы</option>
6+
<option>За размещение</option>
7+
<option>qwerty</option>
8+
</select>
9+
<input type="submit" value="Submit" />
10+
</form>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)