Skip to content

Commit 4837073

Browse files
authored
fix(webapi): selectOption method (#4157)
trim text content value
1 parent 439364e commit 4837073

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

lib/helper/Playwright.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ class Playwright extends Helper {
18051805
let optionToSelect = '';
18061806

18071807
try {
1808-
optionToSelect = await el.locator('option', { hasText: option }).textContent();
1808+
optionToSelect = (await el.locator('option', { hasText: option }).textContent()).trim();
18091809
} catch (e) {
18101810
optionToSelect = option;
18111811
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<html>
2+
<body>
3+
<form action="/form/complex" method="POST">
4+
<label for="age">Select your age</label>
5+
<select name="age" id="age">
6+
<option value="child">
7+
below 13
8+
</option>
9+
<option value="teenage">
10+
13-21
11+
</option>
12+
<option value="adult">
13+
21-60
14+
</option>
15+
<option value="oldfag" selected="selected">
16+
60-100
17+
</option>
18+
<option value="dead">
19+
100-210
20+
</option>
21+
</select>
22+
<input type="submit" value="Submit" />
23+
</form>
24+
</body>
25+
</html>

test/helper/webapi.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,13 @@ module.exports.tests = function () {
433433
await I.click('Submit');
434434
assert.deepEqual(formContents('like'), ['play', 'adult']);
435435
});
436+
437+
it('should select option by label and option text with additional spaces', async () => {
438+
await I.amOnPage('/form/select_additional_spaces');
439+
await I.selectOption('Select your age', '21-60');
440+
await I.click('Submit');
441+
assert.equal(formContents('age'), 'adult');
442+
});
436443
});
437444

438445
describe('#executeScript', () => {

0 commit comments

Comments
 (0)