Select tab does not work after add tab is called in Jquery.UI 1.8.2

Select tab does not work after add tab is called in Jquery.UI 1.8.2

I believe the folowing code should add a tab to a Jquery tabPane the same way normal browsers do this.

                var i = 1;
                $("#add").click(function(){
                    var index = $("#tabs").tabs('option', 'selected');
                    $("#tabs").tabs('add','#test'+i, "ADDED ME", index);
                    i+=1;
                    console.log("set index");
                    $("#tabs").tabs('select', index);
                    console.log("index has been set");
                });

The first time this is called everything works fine. However the second time, the select statement will yield no result, tho it is executed. So the last tab will be selected instead of the newly created tab. I could not find any posts about this. Is it a bug or am i doing something wrong?

I added a test case as attachment.

Kind regards