Commit 778114e0 778114e05ff70e28cd22177331ba68af29f983f8 by Matt DuVall

refs #615: sendkeys does not work with contenteditable

This fixes an issue where sendKeys does not fill in the text on
contentEditable elements. The element is checked in the attributes
object whether `contenteditable` is true and clicks the element to
sendKeys to.
1 parent eb4be25d
......@@ -1554,8 +1554,12 @@ Casper.prototype.sendKeys = function(selector, keys, options) {
supported = ["color", "date", "datetime", "datetime-local", "email",
"hidden", "month", "number", "password", "range", "search",
"tel", "text", "time", "url", "week"],
isTextInput = false;
if (tag === 'textarea' || (tag === 'input' && (typeof type === 'undefined' || supported.indexOf(type) !== -1))) {
isTextInput = false,
isTextArea = tag === 'textarea',
isValidInput = tag === 'input' && (typeof type === 'undefined' || supported.indexOf(type) !== -1),
isContentEditable = !!elemInfos.attributes.contenteditable;
if (isTextArea || isValidInput || isContentEditable) {
// clicking on the input element brings it focus
isTextInput = true;
this.click(selector);
......
......@@ -3,5 +3,6 @@
<body>
<div class="tester testo testme" data-stuff="beautiful string"></div>
<div class="tester testo testme" data-stuff="not as beautiful string"></div>
<div id="content-editable-div" contenteditable="true"></div>
</body>
</html>
\ No newline at end of file
......
......@@ -27,6 +27,7 @@
<form id="no-type-test-form" action="#" enctype="multipart/form-data">
<input name="notype">
<form>
<script>
(function () {
'use strict';
......
......@@ -20,7 +20,17 @@ casper.test.begin('sendKeys() tests', 4, function(test) {
values = this.getFormValues('form#no-type-test-form');
test.assertEquals(values.notype, "I have no type.",
'Casper.sendKeys() sends keys to given input without type attribute');
}).run(function() {
test.done();
});
});
casper.test.begin('sendKeys() works on content-editable elements', function(test) {
casper.start('tests/site/elementattribute.html', function() {
this.click('#content-editable-div');
this.sendKeys('#content-editable-div', 'A Clockwork Orange');
}).then(function() {
test.assertSelectorHasText('#content-editable-div','A Clockwork Orange');
}).run(function() {
test.done();
});
......