Skip to content

Instantly share code, notes, and snippets.

@andrewnicols
Created February 3, 2020 23:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save andrewnicols/a50ee7ab196f11c21a5a1bc9b5ff2b4c to your computer and use it in GitHub Desktop.
<?php
namespace Facebook\WebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
require_once('vendor/autoload.php');
// start Chrome with 5 second timeout
$host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = DesiredCapabilities::chrome();
$driver = RemoteWebDriver::create($host, $capabilities, 5000);
$driver->get('http://localhost/test/');
function isAlertPresent($driver){
try{
$driver->wait(10)->until(WebDriverExpectedCondition::alertIsPresent());
$driver->switchTo()->alert()->accept();
return true;
} catch (Exception $ex) {
return false;
}
}
$alertFound = isAlertPresent($driver);
// close the browser
$driver->quit();
var_dump($alertFound);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment