Added dynamic wait for loading and script execution.