1<?php 2 3namespace Facebook\WebDriver; 4 5use Facebook\WebDriver\Remote\DriverCommand; 6use Facebook\WebDriver\Remote\ExecuteMethod; 7 8/** 9 * An abstraction allowing the driver to manipulate the javascript alerts 10 */ 11class WebDriverAlert 12{ 13 /** 14 * @var ExecuteMethod 15 */ 16 protected $executor; 17 18 public function __construct(ExecuteMethod $executor) 19 { 20 $this->executor = $executor; 21 } 22 23 /** 24 * Accept alert 25 * 26 * @return WebDriverAlert The instance. 27 */ 28 public function accept() 29 { 30 $this->executor->execute(DriverCommand::ACCEPT_ALERT); 31 32 return $this; 33 } 34 35 /** 36 * Dismiss alert 37 * 38 * @return WebDriverAlert The instance. 39 */ 40 public function dismiss() 41 { 42 $this->executor->execute(DriverCommand::DISMISS_ALERT); 43 44 return $this; 45 } 46 47 /** 48 * Get alert text 49 * 50 * @return string 51 */ 52 public function getText() 53 { 54 return $this->executor->execute(DriverCommand::GET_ALERT_TEXT); 55 } 56 57 /** 58 * Send keystrokes to javascript prompt() dialog 59 * 60 * @param string $value 61 * @return WebDriverAlert 62 */ 63 public function sendKeys($value) 64 { 65 $this->executor->execute( 66 DriverCommand::SET_ALERT_VALUE, 67 ['text' => $value] 68 ); 69 70 return $this; 71 } 72} 73