Protractor - switch tabs error

拟墨画扇 提交于 2019-12-11 12:53:34

问题


I'm trying to switch to another tab and use controls on that new tab and I get this error:

UnknownError: null value in entry: name=null

this is the test (the important part):

element(by.repeater("project in projects").row(1).column("{{project.name}}")).click().then(function(){

       flow.timeout(5000);
       $('.project-data a').click().then(function () {
            browser.getAllWindowHandles().then(function (handles) {

         flow.timeout(5000);

            browser.switchTo().window(handles[1]).then(function () {
            browser.sleep(5000);
            browser.ignoreSynchronization = true;

           });

there is other part in the test but it's not relevant since I get the error in this part. the flow is this: after clicking the link, the tab is opened, seems like it switches to the new tab - and then it fails and closes the window.


回答1:


Instead of flow.timeout(5000) use browser.wait like so:

browser.wait(function() {
    return handles.length > 1
}, 5000);

and instead of the second flow.timeout(5000) use:

browser.wait(function() {
    return browser.getCurrentUrl().then(function (url){
        return url = "url of the second tab";
    });
}, 5000);

It looks cleaner, better handled, and most importantly, will do the job



来源:https://stackoverflow.com/questions/32859590/protractor-switch-tabs-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!