Search code examples
javascriptweb-scrapingphantomjsconfirm

confirm alert window in phantom.js


i have this function which find button and click it, but after that alert appears and i need to confirm it using phantom.js

function() {
  page.evaluate(function() {
    $('.item-list clicked').first().find($('.comment-delete')).find('a').click();
  })
}

may be i can emulate function which call alert whithout click immediately ? or use function waitFor for waiting this alert?(unlikely this, waitFor waiting only for DOM objects i think so)


Solution

  • As far as I know, Phantom.JS is headless. The only thing you can do is get the context of the alert with

    window.onAlert = function(alertText){
        ...
       }
    

    but no more than this I think. You cannot either close (in general) or render (in Phantom.JS) the alert programmatically.

    Some sources:
    * Render JavaScript alerts with Phantom.JS
    * Close alert programmatically