How to handle java script alert

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to handle java script alert

tulsi.tester
Hi,

Please let me know how to handle java script alert through RC. My java script alert has OK button only.

I used

if(selenium.isAlertPresent())

selenium.chooseOkOnNextConfirmation();

But it is not working. Please find the attachment for the alert.

Reply | Threaded
Open this post in threaded view
|

Re: How to handle java script alert

softwaretestingforum
Administrator
Can you try -

selenium.getConfirmation()
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: How to handle java script alert

tulsi.tester
Hi Tarun,

The scenario is after entering the data into the text field i need to click on next button. If any alert pop-ups i need to click on OK button (because it has only ok button). I followed the following process

selenium.click("Next button");

if(selenium.isAlertPresent())
{
         selenium.getConfirmation();
}

It is also not working for me. Am i doing correct? let me know if i am on the wrong path.
Reply | Threaded
Open this post in threaded view
|

Re: How to handle java script alert

softwaretestingforum
Administrator
Hi Tulsi,

What do you mean by "not working"? Do you mean alert stays on page?
Using Selenium1 you would not be able to see alert on page and the operation of clicking on ok would happen in back ground. If it does not work then you should see alert stays on page. Do you?

On a different note, it is far easy to handle alerts in Selenium 2 then in Selenium 1. If you have just begun with selenium then I suggest to switch to Selenium 2.
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: How to handle java script alert

tulsi.tester
Hi Tarun,

I am not able to see the alert stays on the page. And I am getting exception as

ERROR: There were no confirmations

I think we would us getConfirmation() method only for confirmations (say like ok or cancel button). But how to pass this alert. As of now we are middle of our project. so there is no chance to move to webdriver. Any alternate solution?
Reply | Threaded
Open this post in threaded view
|

Re: How to handle java script alert

softwaretestingforum
Administrator
Can you try -
selenium.getAlert()
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: How to handle java script alert

tulsi.tester
Hi Tarun,

It' correct now i am able to handle the alert. I followed the below process

if(selenium.isAlertPresent())

{
        selenium.getAlert()         //which resembles clicking on OK button

}

Thank you tarun