How to handle confirmation box using Selenium


package com.selenium.pack;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;

public class ConfirmationDemo extends SeleneseTestCase{

    @Before
    public void setUp() throws Exception {
        SeleniumServer ss=new SeleniumServer();
        ss.start();
        selenium=new DefaultSelenium("localhost",4444,"firefox", "http://");
        selenium.start();
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void test() throws InterruptedException {
        selenium.open("softwaretesting-guru.blogspot.in/p/online-training.html");
        selenium.windowMaximize();
        //click on selenium practice page link
        selenium.click("link=Selenium Practice page");
        Thread.sleep(7000);
        System.out.println("Clicking on Confirmation button");
        //click on confirmation button
        selenium.click("//input[@type='button' and @Value='Display a confirm box']");
        Thread.sleep(2000);
        selenium.getConfirmation();
        System.out.println("Get Confirmation");
        Thread.sleep(2000);
        //click on ok from confirmation box
        System.out.println("Choose Ok On Confimation");
        selenium.chooseCancelOnNextConfirmation();
        System.out.println("Confirmation handled");
        Thread.sleep(6000);
 
    }

}

No comments:

Post a Comment