【问题标题】:Error when trying to switch back to the original browser window using intern leadfoot尝试使用实习生 Leadfoot 切换回原始浏览器窗口时出错
【发布时间】:2016-04-27 18:00:51
【问题描述】:

当我调用 switchToWindow(handle) 时出现以下错误: 条目中的空值:name=null

当我尝试切换并且句柄不为空或为空时,原始窗口仍然打开。这是我正在使用的代码:

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);

【问题讨论】:

    标签: intern leadfoot


    【解决方案1】:

    命令链是单个 JavaScript 表达式。这意味着链中所有调用的所有参数都被同时评估一次。当handle 在靠近链顶部的then 回调中分配时,它不会影响链底部的switchToWindow 调用,因为handle 的值在@ 之前已经被评估曾经执行过 987654325@ 回调。

    如果您想在链的早期保留对值的引用,并在以后使用它,那么这两种用法都应该在 then 回调中。

    return session
        ...
        .then(function (currentHandle) {
            handle = currentHandle;
        })
        ...
        .then(function () {
            return session.switchToWindow(handle);
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-07
      • 1970-01-01
      • 2013-05-23
      • 1970-01-01
      • 2019-12-14
      • 1970-01-01
      相关资源
      最近更新 更多