问题
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