Can you at least confirm that I understand the problem correctly, i.e. that Selenium doesn't call HtmlUnit's setAlertHandler?Thanks,Ron--
On Thursday, November 15, 2012 1:46:42 PM UTC+2, Ron Inbar wrote:Hi,I'm not really a Selenium developer but I posted my question to the Selenium Users group and didn't get any replies so I thought maybe I'll have more luck here.My problem is handling an alert using the WebDriver protocol and HtmlUnit. From the Selenium server's output (attached below) it appears that there is no way to do it because Selenium doesn't install an alert handler in HtmlUnit.
My code is in PHP so I communicate with the Selenium server via the WebDriver wire protocol, not the Java API.What I do is send a /session/:sessionId/alert_text request to the Selenium server and check the response to see if it contains a NoAlertPresent error.This works fine when I use the Chrome driver, but when I switch to HtmlUnit it breaks down.I found that HtmlUnit has a setAlertHandler method. Is there a technical reason that Selenium doesn't use it?Thanks,RonHere is my code (it uses Nearsoft's PHP Selenium Client):$submitButton = $this->driver->findElement(By::id('btn_submit'));$submitButton->click();// Probe for a validation error.try {$alertText = $this->driver->getAlertText();$this->driver->dismissAlert();} catch (\SeleniumClient\Http\SeleniumNoAlertOpenErrorException $exc) {return new VerificationPage($this->driver);}if (false !== stripos($alertText, Resources::inputErrorMessage)) {throw new InputErrorException($alertText);}When no alert is present I see the following output:
14:04:21.683 INFO - Executing: [get alert text] at URL: /session/1351512102002/alert_text)
14:04:21.687 WARN - Exception thrown
java.lang.UnsupportedOperationException: alert()
at org.openqa.selenium.htmlunit.HtmlUnitDriver$HtmlUnitTargetLocator.alert(HtmlUnitDriver.java:978)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringTargetLocator.alert(EventFiringWebDriver.java:592)
at org.openqa.selenium.remote.server.handler.GetAlertText.call(GetAlertText.java:31)
at org.openqa.selenium.remote.server.handler.GetAlertText.call(GetAlertText.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:150)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
14:04:21.720 WARN - Exception: alert()
When there is an alert I see the following output:
14:14:39.502 WARN - window.alert("Input error - please correct the highlighted spaces:
- First name
- Last name
- Street, No.
- post code
- Location
- Telephone (only for further questions)
- Please choose payment method
- Please choose delivery method
") no alert handler installed
14:14:39.541 INFO - Done: /session/1351512102005/element/45/click
...and the rest looks exactly as in the first case, as if the alert never happened:
14:15:42.926 INFO - Executing: [get alert text] at URL: /session/1351512102005/alert_text)
14:15:42.926 WARN - Exception thrown
java.lang.UnsupportedOperationException: alert()
at org.openqa.selenium.htmlunit.HtmlUnitDriver$HtmlUnitTargetLocator.alert(HtmlUnitDriver.java:978)
at org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringTargetLocator.alert(EventFiringWebDriver.java:592)
at org.openqa.selenium.remote.server.handler.GetAlertText.call(GetAlertText.java:31)
at org.openqa.selenium.remote.server.handler.GetAlertText.call(GetAlertText.java:1)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:150)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
14:15:42.927 WARN - Exception: alert()
--