Error in ALERT PROGRAM

package automationtesting;

import java.util.Set;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class Alert {

public static WebDriver driver;

public static void main(String[] args) {

// Create a new instance of the Firefox driver

driver = new FirefoxDriver();

// Put an Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// Launch the URL

driver.get(“http://www.toolsqa.com/automation-practice-switch-windows/”);

// Click on the Button “Alert Box”

driver.findElement(By.name(“Alert Box”)).click();

// Switch to JavaScript Alert window

Alert myAlert = driver.switchTo().alert();

// Accept the Alert

myAlert.accept();

// Close Original window

driver.close();

}

}

sir when i am running this program on eclipse it is showing error on     // Switch to JavaScript Alert window

Alert myAlert = driver.switchTo().alert();

// Accept the Alert

myAlert.accept();

this statement .plz tellme how to resolve it

Add Comment
2 Answer(s)

What is the error? How can some one resolve this without the error? Please provide the error description and stack trace with the question.

Virender

Virender Singh Professor Answered on May 8, 2015.
Add Comment

According to your program, below line is wrong


// Click on the Button “Alert Box”
driver.findElement(By.name(“Alert Box”)).click();

Please do modify


// Click on the Button “Alert Box”
driver.findElement(By.id("alert")).click();

I think this will work..

RavinderReddy Train Answered on May 8, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.