How to handle a javascript alert window using PHP behat/mink selenium2 chrome webdriver
Could you check with this
$this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
or
Could you try updating ConfirmPopup function in featureContext.php file as follows
public function iConfirmPopup(){$this->getMainContext()->getSession()->getDriver()->getWebDriverSession()->accept_alert();}
add this in featureContext.php file
Reference Link solution to use alert(), confirm() and prompt() in Selenium2Driver
You don't need to create Selenium2Driver for this method.For Behat 3 this should work if you add it in an object that extends Page object.
public function iConfirmThePopup(){ $i = 0; while($i < 5) { try { $this->getDriver()->getWebDriverSession()->accept_alert(); break; } catch(NoAlertOpenError $e) { sleep(1); $i++; } }}
and add to the beginning of the class:
use WebDriver\Exception\NoAlertOpenError;
You can customize the method according to your needs, you can remove the while and the try-catch if you don't need them.
UPD: code formatting fixed
I find this function is really working for me:
public function acceptAlert(){ $driver = $this->getDriver(); if ($driver instanceof Selenium2Driver) { for ($i = 0; $i < 10; $i++) { try { $driver->getWebDriverSession()->accept_alert(); break; } catch (NoAlertOpenError $e) { sleep(2); $i++; } } }}