js切换到一个框架

js切换到一个框架

本文介绍了用Nightwatch.js切换到一个框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试的UI正在使用iframe。我试图通过.frame(0)调用切换到那个iframe。

the UI I am testing is using an iframe. I am trying to switch to that iframe with the ".frame(0)" call.

module.exports = {
    "test" : function (browser) {
    browser
        .url("my_url")
        .waitForElementVisible(".frame-application-scroll-wrapper", 30000)
        .frame(0)
        .waitForElementPresent("#page-content", 30000)
        .end();
    }
};

然而,#page-content从未见过,这让我觉得更改帧命令不起作用(但两者都没有返回任何错误。)

However, #page-content is never seen which makes me think that the change frame command did not work (but returns no error neither).

任何想法?

谢谢,
Paul

Thanks,Paul

推荐答案

正如Neoaptt所提到的(谢谢!)问题是iframe元素不存在或未加载。添加暂停解决了我的问题。

as Neoaptt mentioned (Thanks!) the issue was that the iframe element was either not present or not loaded. Adding a pause solved my issue.

顺便说一下,如果要退出所选框架,则应使用.frame(null)

By the way, if you want to exit the selected frame you should use ".frame(null)"

module.exports = {
    "test" : function (browser) {
    browser
        .url("my_url")
        .waitForElementVisible(".frame-application-scroll-wrapper", 30000)
        // give time to the iframe to be available
        .pause(5000)
        .frame(0)
                .waitForElementPresent("#page-content", 30000)
                .frame(null)
         // we are now back to the main page
         // ... more code here ...
         .end();
    }
};

还有助于我调试的是使用--verbose选项,例如:

What also helped me to debug was to use the --verbose option, for example:

nightwatch -t tests/test4.js --verbose

这将在您的终端显示nodejs和selenium之间交换的所有数据。

This will display in your terminal all the data exchanged between nodejs and selenium.

谢谢,
Paul

Thanks,Paul

这篇关于用Nightwatch.js切换到一个框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 20:22