Skip to content

Commit

Permalink
support W3C get active element command
Browse files Browse the repository at this point in the history
/element/active requires POST method in JWP but W3C WebDriver spec
requires GET method.

https://www.w3.org/TR/webdriver/#get-active-element

This patch checks remote WebDriver server speaks JWP or W3C on creating
a session and remember it. Then switch method of /element/active
looksing the flag.
  • Loading branch information
rhysd committed Oct 27, 2019
1 parent 7d6d9b1 commit 7bfdf92
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -1987,8 +1987,9 @@ commands.dismissAlert = function() {
*/
commands.active = function() {
var cb = findCallback(arguments);
var method = this.w3c ? 'GET' : 'POST';
this._jsonWireCall({
method: 'POST'
method: method
, relPath: '/element/active'
, cb: callbackWithData(cb, this)
});
Expand Down
2 changes: 2 additions & 0 deletions lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ Webdriver.prototype._init = function() {
try{
jsonData = JSON.parse(data);
_this.sessionID = jsonData.value ? jsonData.value.sessionId : false;
_this.w3c = false;
resData = jsonData.value;

if(!_this.sessionID && jsonData.status === 0 ){
_this.sessionID = jsonData.sessionId;
_this.w3c = true;
}
} catch(ignore){}
if(!_this.sessionID){
Expand Down

0 comments on commit 7bfdf92

Please sign in to comment.