In these cases, we have to use the wait_for_condition() selenium API.
Key thing to observe here is that the code that you write in the condition is in javascript.
In the following example, I am waiting for the alert for 60000 milliseconds. This alert is poped up after updating the page based on the AJAX response.
my $cond = "try{ if(selenium.getAlert().indexOf('Package successfully deployed') > -1){true;} } catch(ex) {}";
$Common::sel->wait_for_condition($cond, 60000);