8000 refs #615: sendkeys does not work with contenteditable by mduvall · Pull Request #620 · casperjs/casperjs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 19, 2020. It is now read-only.

refs #615: sendkeys does not work with contenteditable #620

Merged
merged 2 commits into from
Sep 12, 2013
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/modules/casper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~

Expand Down
8 changes: 6 additions & 2 deletions modules/casper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/site/elementattribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 1 addition & 0 deletions tests/site/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<form id="no-type-test-form" action="#" enctype="multipart/form-data">
<input name="notype">
<form>

<script>
(function () {
'use strict';
Expand Down
10 changes: 10 additions & 0 deletions tests/suites/casper/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
0