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 ...@@ -1459,6 +1459,8 @@ Sends native keyboard events to the element matching the provided :doc:`selector
1459 1459
1460 .. versionadded:: 1.1 1460 .. versionadded:: 1.1
1461 1461
1462 The currently supported HTMLElements that can receive keyboard events from ``sendKeys`` are ``<input>``, ``<textarea>``, and any HTMLElement with attribute ``contenteditable="true"``.
1463
1462 Options 1464 Options
1463 ~~~~~~~ 1465 ~~~~~~~
1464 1466
......
...@@ -1554,8 +1554,12 @@ Casper.prototype.sendKeys = function(selector, keys, options) { ...@@ -1554,8 +1554,12 @@ Casper.prototype.sendKeys = function(selector, keys, options) {
1554 supported = ["color", "date", "datetime", "datetime-local", "email", 1554 supported = ["color", "date", "datetime", "datetime-local", "email",
1555 "hidden", "month", "number", "password", "range", "search", 1555 "hidden", "month", "number", "password", "range", "search",
1556 "tel", "text", "time", "url", "week"], 1556 "tel", "text", "time", "url", "week"],
1557 isTextInput = false; 1557 isTextInput = false,
1558 if (tag === 'textarea' || (tag === 'input' && (typeof type === 'undefined' || supported.indexOf(type) !== -1))) { 1558 isTextArea = tag === 'textarea',
1559 isValidInput = tag === 'input' && (typeof type === 'undefined' || supported.indexOf(type) !== -1),
1560 isContentEditable = !!elemInfos.attributes.contenteditable;
1561
1562 if (isTextArea || isValidInput || isContentEditable) {
1559 // clicking on the input element brings it focus 1563 // clicking on the input element brings it focus
1560 isTextInput = true; 1564 isTextInput = true;
1561 this.click(selector); 1565 this.click(selector);
......
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
3 <body> 3 <body>
4 <div class="tester testo testme" data-stuff="beautiful string"></div> 4 <div class="tester testo testme" data-stuff="beautiful string"></div>
5 <div class="tester testo testme" data-stuff="not as beautiful string"></div> 5 <div class="tester testo testme" data-stuff="not as beautiful string"></div>
6 <div id="content-editable-div" contenteditable="true"></div>
6 </body> 7 </body>
7 </html> 8 </html>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
27 <form id="no-type-test-form" action="#" enctype="multipart/form-data"> 27 <form id="no-type-test-form" action="#" enctype="multipart/form-data">
28 <input name="notype"> 28 <input name="notype">
29 <form> 29 <form>
30
30 <script> 31 <script>
31 (function () { 32 (function () {
32 'use strict'; 33 'use strict';
......
...@@ -20,7 +20,17 @@ casper.test.begin('sendKeys() tests', 4, function(test) { ...@@ -20,7 +20,17 @@ casper.test.begin('sendKeys() tests', 4, function(test) {
20 values = this.getFormValues('form#no-type-test-form'); 20 values = this.getFormValues('form#no-type-test-form');
21 test.assertEquals(values.notype, "I have no type.", 21 test.assertEquals(values.notype, "I have no type.",
22 'Casper.sendKeys() sends keys to given input without type attribute'); 22 'Casper.sendKeys() sends keys to given input without type attribute');
23 }).run(function() {
24 test.done();
25 });
26 });
23 27
28 casper.test.begin('sendKeys() works on content-editable elements', function(test) {
29 casper.start('tests/site/elementattribute.html', function() {
30 this.click('#content-editable-div');
31 this.sendKeys('#content-editable-div', 'A Clockwork Orange');
32 }).then(function() {
33 test.assertSelectorHasText('#content-editable-div','A Clockwork Orange');
24 }).run(function() { 34 }).run(function() {
25 test.done(); 35 test.done();
26 }); 36 });
......