Need sample code with Robot in java for alert box handling

287 views
Skip to first unread message

Reaz Patwary

unread,
Jul 5, 2011, 4:12:21 PM7/5/11
to Selenium Users
I have alert box for deleting a specific row from a table. I tried
chooseOkONNextConfirmation method and it doesnt work. Tried robot but
not sure i did it right as its not working. Please guys any sample
code in java will help a lot

or any solution to handle this alert box?????

thanks
RP

Arthy

unread,
Jul 6, 2011, 5:08:40 PM7/6/11
to Selenium Users

Using webdriver you can handle the alert box, try the below code

webdriver.switchTo().alert().accept() - accepts the alert box
webdriver.switchTo().alert().dismiss() - dismiss the alert box

Emil Tomov

unread,
Jul 7, 2011, 2:12:38 AM7/7/11
to seleniu...@googlegroups.com
I use this to accept or cancel firefox download or open file dialog (damn firefox y u not automate?)
public class CloseConfirmPopUp implements Runnable
{
    @Override
    public void run()
    {
        try
        {
            Robot robot = new Robot();
            robot.delay(1000);
            robot.keyPress(KeyEvent.VK_ENTER);
            robot.keyRelease(KeyEvent.VK_ENTER);
        }
        catch(AWTException e)
        {
            e.printStackTrace();
        }
        return;
    }
}
public class CloseCancelPopUp implements Runnable
{

    public void run()
    {
        try
        {
            Robot robot = new Robot();
            robot.delay(10000);
            robot.keyPress(KeyEvent.VK_CANCEL);
        }
        catch(AWTException e)
        {
            e.printStackTrace();
        }
        return;
    }
}


--
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.


Reaz Patwary

unread,
Jul 7, 2011, 3:11:13 PM7/7/11
to Selenium Users
Thanks for your replay guys.

Emil ,

Do i have to create new class to do it or just cal copy and paste the
try catch block to my code??

RP

Reaz Patwary

unread,
Jul 8, 2011, 2:47:40 PM7/8/11
to Selenium Users
Thanks a Lot Emil. Though i have create new thread...Still thanks man
you are the best!
RP

On Jul 7, 2:12 am, Emil Tomov <bem...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages