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);
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
handleis assigned in athencallback near the top of the chain, it won't affect theswitchToWindowcall at the bottom of the chain, because the value ofhandlehad already been evaluated before thethencallback 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
thencallbacks.