Commit 7897d32a 7897d32aa6d435ccae556d8909c5f6f319735b7d by Nicolas Perriault

Merge pull request #620 from mduvall/content-editable-sendkeys

refs #615: sendkeys does not work with contenteditable
2 parents 2ab46f47 73393f71
......@@ -1459,6 +1459,8 @@ Sends native keyboard events to the element matching the provided :doc:`selector
.. versionadded:: 1.1
The currently supported HTMLElements that can receive keyboard events from ``sendKeys`` are ``<input>``, ``<textarea>``, and any HTMLElement with attribute ``contenteditable="true"``.
Options
~~~~~~~
......
......@@ -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();
});
......