Saturday 10 March 2012

JavaScript Prompt Dialog Box [JavaScript alert messages ] in web application using selenium automation testing


importorg.openqa.selenium.Alert;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.firefox.FirefoxDriver;

//JavaScript Prompt Dialog Box  [JavaScript alert messages ] in web application using selenium automation testing
public classJavaScriptAlert_LearnSeleniumWithJasmine {

       public static void main(String[] args) throws InterruptedException {
              WebDriver Jasminedriver = new FirefoxDriver();
              Jasminedriver.get("http://www.javascripter.net/faq/prompt.htm#top");
             
              Jasminedriver.findElement(By.xpath("html/body/p[1]/table/tbody/tr/td[1]/form/input")).click();
              Alert javascriptAlert = Jasminedriver.switchTo().alert();
              Thread.sleep(5000);
              javascriptAlert.accept();
              System.out.println("Jasmine OK");
             
              javascriptAlert = Jasminedriver.switchTo().alert();
             
              Thread.sleep(5000);
              javascriptAlert.accept();
              System.out.println("Jasmine OK");
             
              Jasminedriver.findElement(By.xpath("html/body/p[1]/table/tbody/tr/td[1]/form/input")).click();
             
              javascriptAlert = Jasminedriver.switchTo().alert();
              Thread.sleep(5000);
              javascriptAlert.dismiss();
              System.out.println("Jasmine OK");
             

              javascriptAlert = Jasminedriver.switchTo().alert();
             
              Thread.sleep(5000);
              javascriptAlert.accept();
              System.out.println("Jasmine OK");
             
       }

}