+2 votes
in Software Testing by (190 points)
In my application after save alerts come , are you sure want to change it? like this how i can manage in selenium ?

2 Answers

+2 votes
by Expert (4.6k points)
selected by
Best answer
you can try this it will accepect your alert box.


public void testAlertOk()
    //Now we would click on AlertButton

    try {
        //Now once we hit AlertButton we get the alert
        Alert alert = driver.switchTo().alert();
        //Text displayed on Alert using getText() method of Alert class
        String AlertText = alert.getText();
        //accept() method of Alert Class is used for ok button
        //Verify Alert displayed correct message to user
        assertEquals("this is alert box",AlertText);
    } catch (Exception e) {


+2 votes
by (960 points)

You can also see these methods :

Moving Between Windows and Frames

Some web applications have many frames or multiple windows. WebDriver supports moving between named windows using the “switchTo” method:


All calls to driver will now be interpreted as being directed to the particular window. But how do you know the window’s name? Take a look at the javascript or link that opened it:

<a href="somewhere.html" target="windowName">Click here to open a new window</a>

Alternatively, you can pass a “window handle” to the “switchTo().window()” method. Knowing this, it’s possible to iterate over every open window like so:

for (String handle : driver.getWindowHandles()) {


You can also switch from frame to frame (or into iframes):


It’s possible to access subframes by separating the path with a dot, and you can specify the frame by its index too. That is:


by Expert (5.9k points)
+1 for such a nice explanation.

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated