Issue with jQuery UI select menu: Uncaught Error: no such method 'instance' for menu widget instance

Issue with jQuery UI select menu: Uncaught Error: no such method 'instance' for menu widget instance

I have a drop down list(select list) with ID 'TestList'. I want to use this as selectmenu from jQuery UI. This drop down is getting dynamically populated so initially there are no options to this select list. 
In the scripts section, I am first initializing the select list with select menu as: 
  1. $("#TestList").selectmenu();
Next, I want to dynamically populate it with data, so I am doing this:
  1. for (var i = 0; i < data.length; i++) {
  2.                 
  3.                 $('#TestList').val(data[i]);
  4.                 $("#TestList").selectmenu("refresh");
  5.             } 
But the problem is, it throws  Uncaught Error: no such method 'instance' for menu widget instance.
I am using the latest jQuery UI package(jquery-ui-1.12.1.custom) and jQuery 1.9
Please help me solve this issue..