1

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.

giri-sh
  • 6,934
  • 2
  • 25
  • 50
user2880391
  • 2,683
  • 7
  • 38
  • 77
  • correct me if i'm wrong, but isn't browser.getAllWindowHandles() gets all WINDOWS of the browser that are open? you say it switches to the tab and fails and closes, to me it seems the link just opens a tab and switches focus, and you dont succeed to switch to that tab. – vrachlin Sep 30 '15 at 07:15
  • I was also wondering about it, but it seems like Windows and Tabs switched the same way.. – user2880391 Sep 30 '15 at 07:18
  • Can you print `browser.getAllWindowHandles()` and see the value that you get? If you get 2 then what you do is valid, if not, then you should not be switching the window. When you switch the tabs in the same page i don't think window handles is required. – giri-sh Sep 30 '15 at 07:22
  • I used this as reference: http://stackoverflow.com/questions/26798020/protractor-switch-to-previous-tab. anyway - do you know how do I switch between tabs if not through browser.getAllWindowHandles()? I've tried printing the 'getAllWindoHandles()' and got a long object. – user2880391 Sep 30 '15 at 07:30
  • sorry for the confusion caused, I asked if you could print the 'getAllWindowHandles()' result. i.e, `handles.length` value. However if on click there is a new tab thats opening in your browser, then above method should help you out. Also check if a new browser tab is really being opened when your code executes. – giri-sh Sep 30 '15 at 07:55
  • thanks for that great suggestions. when checking the 'handles.length' I got 1 which made me understand it happens too fast. what solved the problem was adding 'flow.timeout(5000)' between clicking the link that opens the new tab and the 'getAllWindowHandles()'. I'm not sure that's the best solution, but it works now. – user2880391 Sep 30 '15 at 08:24
  • Related? http://stackoverflow.com/questions/30012157/cant-switch-windows-during-testing-by-webdriver-js. – alecxe Sep 30 '15 at 14:03

1 Answers1

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

vrachlin
  • 817
  • 5
  • 15