Click OK on Alert box

824 views
Skip to first unread message

NagaRaju dasam

unread,
Jul 26, 2010, 1:12:21 AM7/26/10
to Selenium Users
Hi Guys,

In my site when i click on a link i got a confirmation box. that confirmation box is on load event. i used all the possible commands like choose confirmation, key event etc.

I have two questions..

1. Can we write a java code to click on OK button?
2. can we use Java script in selenium?

if possible can any one please send me the code to click ok button...

Nusrat Nilofer

unread,
Jul 26, 2010, 1:27:29 AM7/26/10
to seleniu...@googlegroups.com


Selenium does NOT support JavaScript confirmations that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until you manually click OK. 

try with soln given in http://qtp-help.blogspot.com/2009/07/selenium-handle-dialogs.html#handle_alertbox_onload.


Regards,

Nusrat



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

NagaRaju dasam

unread,
Jul 26, 2010, 3:17:02 AM7/26/10
to seleniu...@googlegroups.com
Thanks for the reply..The link you provided does not help me...

Elias Nogueira

unread,
Jul 26, 2010, 6:53:56 AM7/26/10
to seleniu...@googlegroups.com

ranjith

unread,
Jul 26, 2010, 5:45:03 AM7/26/10
to Selenium Users
use getAlert( ) it will work.

--> Retrieves the message of a JavaScript alert generated during the
previous action, or fail if there were no alerts.--> --> Getting an
alert has the same effect as manually clicking 'OK' on alert pop up.

one more thing first u need to identify whether it is a "alert" or
"Confirmation".
Find the below clue also
alerts have the single button i.e OK, where as confirmations have two
optional buttons namely OK and Cancel.

I guess in your case instead using selenium click( locator ) use
fireEvent

void fireEvent(java.lang.String locator, java.lang.String eventName)

Explicitly simulate an event, to trigger the corresponding
"onevent" handler.

Parameters:
locator - an element locator
eventName - the event name, e.g. "focus" or "blur"

One more thing is, if you are having the link means, probably you
might be having the 'onClick' event and this case u have to use the
fireEvent as

fireEvent( String locator, "click");

Note: dont pass onclick in the method, just exclude the "on" for all
the events.

Regards,
Ranjith


On Jul 26, 12:17 pm, NagaRaju dasam <nagaselen...@gmail.com> wrote:
> Thanks for the reply..The link you provided does not help me...
>
>
>
> On Mon, Jul 26, 2010 at 10:57 AM, Nusrat Nilofer <nnilo...@gmail.com> wrote:
>
> > Selenium does NOT support JavaScript confirmations that are generated in a
> > page's onload() event handler. In this case a visible dialog WILL be
> > generated and Selenium will hang until you manually click OK.
>
> > try with soln given in
> >http://qtp-help.blogspot.com/2009/07/selenium-handle-dialogs.html#han...
> > .
>
> > Regards,
>
> > Nusrat
>
> > On Mon, Jul 26, 2010 at 10:42 AM, NagaRaju dasam <nagaselen...@gmail.com>wrote:
>
> >> Hi Guys,
>
> >> In my site when i click on a link i got a confirmation box. that
> >> confirmation box is on load event. i used all the possible commands like
> >> choose confirmation, key event etc.
>
> >> I have two questions..
>
> >> 1. Can we write a java code to click on OK button?
> >> 2. can we use Java script in selenium?
>
> >> if possible can any one please send me the code to click ok button...
>
> >> --
> >> Thanks,
> >> Naga
>
> >>http://testerinyou.blogspot.com/
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "Selenium Users" group.
> >> To post to this group, send email to seleniu...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> selenium-user...@googlegroups.com<selenium-users%2Bunsu...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/selenium-users?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Selenium Users" group.
> > To post to this group, send email to seleniu...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > selenium-user...@googlegroups.com<selenium-users%2Bunsu...@googlegroups.com>
> > .

NagaRaju dasam

unread,
Jul 26, 2010, 8:53:24 AM7/26/10
to seleniu...@googlegroups.com
Hi Guys i tried the method what u said. but it didnt work.

Please see the code and let me know if i did some thing wrong.

import java.awt.Robot;
import java.awt.event.KeyEvent;

import com.thoughtworks.selenium.DefaultSelenium;


public class Confirmation {

public static void click() throws Exception
{
DefaultSelenium selenium=new DefaultSelenium("localhost", 4444, "*firefox", "http://");
selenium.start();
selenium.open("http://www.truepanel.com/");
         selenium.windowMaximize();
         selenium.click("link=Join Moms Panel");//after clicking this link i got confirmation box with two buttons ok and cancel
         Robot robot = new Robot();
         robot.keyPress(KeyEvent.VK_ENTER);
         robot.keyPress(KeyEvent.VK_SPACE);
         selenium.waitForPageToLoad("50000");
         selenium.click("link=Home");
  selenium.waitForPageToLoad("50000");
   
        
}
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
click();
}

}



Thanks,
Naga


To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Auto_tester

unread,
Jul 26, 2010, 8:54:35 AM7/26/10
to Selenium Users
Have you tried using:

selenium.ChooseOkOnNextConfirmation()

NagaRaju dasam

unread,
Jul 26, 2010, 8:55:43 AM7/26/10
to seleniu...@googlegroups.com
Yes Boss i already tried selenium.ChooseOkOnNextConfirmation();

But no use

Thanks,
Naga

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Auto_tester

unread,
Jul 26, 2010, 9:39:54 AM7/26/10
to Selenium Users
Try:

if (selenium.IsAlertPresent())
{
selenium.GetAlert();
> > selenium-user...@googlegroups.com<selenium-users%2Bunsubscribe@go oglegroups.com>
> > .

Elias Nogueira

unread,
Jul 26, 2010, 9:52:07 AM7/26/10
to seleniu...@googlegroups.com
This will work in onload if you put the js code that I mentioned  or if you use a thread sleep to wait for alert appears.

Try to put a Thread.sleep(milliseconds); before the robot command.
But it's a workarround... and you need be careful with it.


Regards!
--
Elias Nogueira, CSTE
elias.n...@gmail.com

CSTE - Certified Software Tester
Blog: http://sembugs.blogspot.com
Twitter: http://twitter.com/eliasnogueira
LinkedIn: http://www.linkedin.com/in/eliasnogueira




To unsubscribe from this group, send email to selenium-user...@googlegroups.com.

adit cool

unread,
Jul 27, 2010, 11:56:33 PM7/27/10
to seleniu...@googlegroups.com
hi naga,
 
Try 
selenium.ChooseOkOnNextConfirmation() ....by the way what IDE are using?

Regards,
Adit

NagaRaju dasam

unread,
Jul 28, 2010, 1:57:27 AM7/28/10
to seleniu...@googlegroups.com
I already tried
selenium.ChooseOkOnNextConfirmation() . it didnt work.

because the confirmation is an onload event. please tell me how to handle onload event.

i m using selenium RC with eclipse

thanks,
Naga

Reply all
Reply to author
Forward
0 new messages