Home C C++ Java Python Perl PHP SQL JavaScript Linux Selenium QT Online Test

Home » Selenium » Solved Programs » Compare text of Alert Box

C Program which prints itself

package com.selenium.test;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Alert1 {

public static void main(String[] args) throws InterruptedException {

 WebDriver driver = new ChromeDriver();



 driver.findElement(B y.xpath(".//*[@id='searchBtn']")).click();

 String actual = driver.switchTo().alert().getText();

 // .dismiss is used to click on the
 // second option in a pop up message
 // driver.switchTo().alert().dismiss();	

 // test will fail because expected is different 
 String expected = "Please select start place";

 if (actual.equalsIgnoreCase(expected)) {
	System.out.println("Test Pass");
 } else {
	System.out.println("Test Failed");