I was having problems with alerts myself using WebDriverBackedSelenium
with the Selenium API methods it provides. I ended up writing a few
methods to handle them that look like the Selenium 1.0 API versions,
but use the WebDriver API instead. The only real difference I see
between your code and mine is that I am doing an accept().
Here is the code if it helps:
/**
* This is identical to the selenium.isAlertPresent() method for
* WebDriverBackedSelenium, in that it checks to see if an alert
message
* is present, except this one works. It uses WebDriver methods
to check to
* see if a JavaScript alert() message is on the screen.
* @return This will return true is an alert message is on the
screen.
*/
public boolean isAlertPresent()
{
try
{
driver.switchTo().alert();
return true;
} // try
catch (NoAlertPresentException Ex)
{
return false;
} // catch
} // isAlertPresent()
/**
* This is identical to the selenium.getAlert() method for
* WebDriverBackedSelenium, in that it gets the text of the alert
message
* and it clicks the OK button to make it go away, except this one
works.
* @return String with the text of the alert message in it.
*/
public String getAlert()
{
Alert alert = driver.switchTo().alert();
String str = alert.getText();
alert.accept();
return str;
} // getAlert()
/**
* This will wait until a JavaScript alert() message is present,
or until
* the timeoutMSec expires.
* @param timeoutMSec The time to wait before throwing an
exception showing
* no alert() message is present.
* @throws Exception
* @see <a href="
http://groups.google.com/group/selenium-users/
browse_thread/thread/e559b59a513630c8/ff4ca846f6c01b5e?lnk=gst&q=alert+
%26+driver#">Post by Mark Collin</a>
*/
public void waitForAlert(int timeoutMSec) throws Exception
{
startTimer(timeoutMSec);
while (!timerExpired && !isAlertPresent())
{
pause(100); // Delay .1 seconds
} // while
if (timerExpired)
throw new Exception("No alert was seen in " + timeoutMSec
+ "MSec.");
else
timer.stop();
} // waitForAlert(int timeoutMSec) throws Exception
On Jan 16, 3:08 am, Rana Banerjee <
ranarbaner...@gmail.com> wrote:
> Hi,
>
> Is there any update on this? This is kind of urgent.
>
> Thanks in advance,
> Rana Banerjee
>