I use Selenium 2.42.0 with Java (in Eclipse) and I need to use as WebDriver a headless browser like HtmlUnit-driver (2.42.2) or PhantomJS (Ghostdriver). It`s important that I can handle alerts in Java (Eclipse), which i trigger on purpose for testing on the tested sites.
I may close the Alert but I need to recognize it somehow in eclipse that there has been an Alert, like getting the Text of the alert or even an Exception that there is a alert present
or like:
if(alert ==true)
var_alert++;
With the FireFoxdriver it is easy but the Alert is not implemented yet in HtmlUnitDriver and PhantomJsdriver by Selenium:
try{
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
System.out.println("Found Alert: " + alert.getText());
alert.accept();
}
catch(Exception e){
System.out.println("Exception " + e);
}
Please help me. Thx!