Articles → SELENIUM → Test validations in web application using Selenium

Test validations in web application using Selenium






Steps









Click to Enlarge






Code


package com.FirstSeleniumProject;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class MyClass {

	public static void main(String[] args) {
		WebDriver driver ;
		String service = "IEDriverServer path";
		System.setProperty("webdriver.ie.driver", service);
		driver = new InternetExplorerDriver();
		driver.get("http://gyansangrah.com/ContactUs.aspx");

		driver.findElement(By.name("ctl00$cphGyanSangrah$btnSubmit")).click();
		//driver.switchTo().alert().accept();
		Alert alert = driver.switchTo().alert();

		String alertMessage = alert.getText();
		alert.accept();

		WebElement emailId =driver.findElement(By.name("ctl00$cphGyanSangrah$txtEmailID"));

		String textInsideInputBox = emailId.getAttribute("value");
		// Check whether input field is blank
		if(textInsideInputBox.trim().equalsIgnoreCase("Your Email ID") &&
				alertMessage.trim().equalsIgnoreCase("Invalid email"))
		{
			System.out.println("Email Validation is fine");
		}

	}
}



Output



Click to Enlarge


Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, April 17, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250