Skip to content

Commit

Permalink
Handle text parameter Element#type
Browse files Browse the repository at this point in the history
fixes #144
  • Loading branch information
John Dorlus authored and jason0x43 committed Jul 17, 2018
1 parent 7960a10 commit fda2777
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,17 @@ Element.prototype = {
*/
type: function (value) {
function getPostData(arrayValue) {
if (self.session.capabilities.isWebDriver) {
return { value: arrayValue.join('').split('') };
var capabilities = self.session.capabilities;
if (capabilities.isWebDriver || capabilities.valueParameterCalledText) {
if (capabilities.valueParameterCalledText) {
// The WebDriver version of `/value` requires the value
// property to be named `text` and to contain a string.
return { text: arrayValue.join('') };
} else {
// Browsers that support WebDriver but use the `value`
// property require it to be a flat array of characters.
return { value: arrayValue.join('').split('') };
}
}
return { value: arrayValue };
}
Expand Down Expand Up @@ -288,7 +297,13 @@ Element.prototype = {
}

// If the input isn't a filename, just post the value directly
return this._post('value', getPostData(value)).then(noop);
return this._post('value', getPostData(value)).then(noop).catch(function(error){
if (error.detail.error === 'invalid argument' &&
!self.session.capabilities.valueParameterCalledText) {
self.session.capabilities.valueParameterCalledText = true;
return self.type(value);
}
});
},

/**
Expand Down
6 changes: 6 additions & 0 deletions Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ Server.prototype = {
capabilities.browserVersion = capabilities.version;
}

// WebDriver Spec now supports [POST] /value receiving a
// parameter named 'text' as a string instead of an array of
// charactrers named 'value'. This was updated in geckodriver as
// of 16.0 but not yet completed in chromedriver.
capabilities.valueParameterCalledText = false;

function supported() { return true; }
function unsupported() { return false; }
function maybeSupported(error) {
Expand Down

0 comments on commit fda2777

Please sign in to comment.