Reputation: 167
I'm getting the following error when I call switchToWindow(handle): null value in entry: name=null
The original window is still open when I try to switch and handle is not null or empty. Here is the code I'm using:
var session = this.remote;
var handle;
return session
.get('http://www.google.com')
.getCurrentWindowHandle()
.then(function (currentHandle) {
console.log('handle: ' + currentHandle);
handle = currentHandle;
})
.execute(function() {
var newWindow = window.open('https://www.instagram.com/', 'insta');
})
.switchToWindow('insta')
.closeCurrentWindow()
.then(function () {
console.log('old handle: ' + handle);
})
.sleep(2000)
.switchToWindow(handle);
Upvotes: 0
Views: 151
Reputation: 3363
A Command chain is a single JavaScript expression. This means that all the arguments to all the calls in the chain are evaluated at once, synchronously. When handle
is assigned in a then
callback near the top of the chain, it won't affect the switchToWindow
call at the bottom of the chain, because the value of handle
had already been evaluated before the then
callback ever executed.
If you want to keep a reference to a value early in a chain, and use it later, both uses should be in then
callbacks.
return session
...
.then(function (currentHandle) {
handle = currentHandle;
})
...
.then(function () {
return session.switchToWindow(handle);
});
Upvotes: 1