Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible fix for a 'selectOption' issue #408

Merged
merged 4 commits into from Feb 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/helper/Nightmare.js
Expand Up @@ -651,7 +651,12 @@ class Nightmare extends Helper {
el = codeceptjs.fetchElement(el);
let found = document.evaluate(locator, el, null, 5);
var current = null;
var items = [];
while (current = found.iterateNext()) {
items.push(current);
}
for (var i = 0; i < items.length; items++) {
current = items[i];
current.selected = true;
var event = document.createEvent('HTMLEvents');
if (!el.multiple) el.value = current.value;
Expand Down
29 changes: 29 additions & 0 deletions test/data/app/view/form/select_onchange.php
@@ -0,0 +1,29 @@
<html>
<body>
<form action="/form/complex" method="POST">
<label>
<div>Select a value:</div>
<div>
<select name="select" id="select">
<option value=""></option>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
</div>
</label>
<input id="submit" disabled="disabled" type="submit" value="Submit" />
</form>
<script>
document.getElementById('select').addEventListener('change', function() {
var submit = document.getElementById('submit');
if (this.value === "") {
submit.setAttributeNode("disabled", "disabled");
} else {
var disabled = submit.getAttributeNode("disabled");
submit.removeAttributeNode(disabled);
}
});
</script>
</body>
</html>
7 changes: 7 additions & 0 deletions test/helper/webapi.js
Expand Up @@ -219,6 +219,13 @@ module.exports.tests = function() {
return assert.equal(formContents('age'), 'adult');
});

it('should select option by label and option text - with an onchange callback', function*() {
yield I.amOnPage('/form/select_onchange');
yield I.selectOption('Select a value', 'Option 2');
yield I.click('Submit');
return assert.equal(formContents('select'), 'option2');
});

it('should select multiple options', function*() {
yield I.amOnPage('/form/select_multiple');
yield I.selectOption('What do you like the most?', ['Play Video Games', 'Have Sex']);
Expand Down