【问题标题】:Accessing Elements on electron webview using spectron使用 spectron 访问电子 webview 上的元素
【发布时间】:2016-05-10 02:27:14
【问题描述】:

我正在尝试自动化一个将其内容加载到 web 视图的电子应用程序。我正在使用 spectron 和 webdriverio。

这是我正在使用的代码。

it('should assess webview', function() {
    var self = this;
    return this.app.client.waitUntilWindowLoaded()
        .windowHandles().then(function(session) {
            self.app.client.switchTab(session.value[1])
            .click("#my-id")
            .then(console.log.bind(console))
            .catch(console.log.bind(console));
        });
});

这似乎不起作用。我不确定我哪里出错了。但是我用过

it('should assess webview', function() {
    var self = this;
    return this.app.client.waitUntilWindowLoaded()
        .windowHandles().then(function(session) {
            self.app.client.switchTab(session.value[1])
            .getSource()
            .then(console.log.bind(console))
            .catch(console.log.bind(console));
        });
});

以上代码确保webview窗口句柄是否正确。它是。请帮忙。谢谢

【问题讨论】:

    标签: webdriver electron webdriver-io


    【解决方案1】:

    我已经检查了代码,使用 spectron 并在里面运行 webview 来模拟这种行为,你的代码工作正常。重新编写代码。希望这会有所帮助。

    it('should assess webview', function() {
        var self = this;
        return this.app.client.waitUntilWindowLoaded()
            .windowHandles().then(function(session) {
                // Need to return the promise back, if promise is
                // it would wait for the state or else app will exit.
                return self.app.client.switchTab(session.value[1])
                .click("#my-id") // check whether selector is present in DOM
                .then(console.log.bind(console))
                .catch(console.log.bind(console));
            });
    });
    

    或

    it('should assess webview', function() {
        var self = this;
        return this.app.client.waitUntilWindowLoaded()
            .windowHandles()
            .then(function(session) {
                // switchTab & window will both focus
                // window or tab which is active
                return this.window(session.value[1])
            })
            .click("#my-id") // check whether selector is present in DOM
            .then(console.log.bind(console))
            .catch(console.log.bind(console));;
    });
    

    【讨论】:

    • 谢谢@kamesh,我会检查的。
    猜你喜欢
    • 2019-11-30
    • 2015-12-23
    • 2017-10-22
    • 1970-01-01
    • 2018-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多