diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 4c0575205..4f9816cbc 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -1805,7 +1805,7 @@ class Playwright extends Helper { let optionToSelect = ''; try { - optionToSelect = await el.locator('option', { hasText: option }).textContent(); + optionToSelect = (await el.locator('option', { hasText: option }).textContent()).trim(); } catch (e) { optionToSelect = option; } diff --git a/test/data/app/view/form/select_additional_spaces.php b/test/data/app/view/form/select_additional_spaces.php new file mode 100755 index 000000000..6f202b7ac --- /dev/null +++ b/test/data/app/view/form/select_additional_spaces.php @@ -0,0 +1,25 @@ + +
+ + + diff --git a/test/helper/webapi.js b/test/helper/webapi.js index b8a1d2010..e50d2ffbd 100644 --- a/test/helper/webapi.js +++ b/test/helper/webapi.js @@ -433,6 +433,13 @@ module.exports.tests = function () { await I.click('Submit'); assert.deepEqual(formContents('like'), ['play', 'adult']); }); + + it('should select option by label and option text with additional spaces', async () => { + await I.amOnPage('/form/select_additional_spaces'); + await I.selectOption('Select your age', '21-60'); + await I.click('Submit'); + assert.equal(formContents('age'), 'adult'); + }); }); describe('#executeScript', () => {