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.
Showing
4 changed files
with
18 additions
and
2 deletions
... | @@ -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 | }); | ... | ... |
-
Please register or sign in to post a comment