/*********************************************************************
Script Summary
Title : Webdriver Script036 : Creating IsElementPresent() method
Author : Gaurav Khanna
*********************************************************************/
package com.gaurav.webdriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class s036_IsElementPresent {
// Declaring variable 'webDriver' of WebDriver Type
WebDriver webDriver;
// Declaring variable 'baseUrl' of String Type
String baseUrl;
@BeforeMethod
public void startUp() throws Exception {
// Initializing FireFox Driver
webDriver = new FirefoxDriver();
// Assigning URL to variable 'baseUrl'
baseUrl = "http://book.theautomatedtester.co.uk";
}
@Test
public void tests036_IsElementPresent() throws Exception {
// Open the link
webDriver.get(baseUrl);
// Maximize browser window
webDriver.manage().window().maximize();
//
if (webDriver.findElement(By.id("verifybutton")) != null) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}
}
@AfterMethod
public void shutDown() throws Exception {
// This will close the browser
webDriver.quit();
}
}
Script Summary
Title : Webdriver Script036 : Creating IsElementPresent() method
Author : Gaurav Khanna
*********************************************************************/
package com.gaurav.webdriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class s036_IsElementPresent {
// Declaring variable 'webDriver' of WebDriver Type
WebDriver webDriver;
// Declaring variable 'baseUrl' of String Type
String baseUrl;
@BeforeMethod
public void startUp() throws Exception {
// Initializing FireFox Driver
webDriver = new FirefoxDriver();
// Assigning URL to variable 'baseUrl'
baseUrl = "http://book.theautomatedtester.co.uk";
}
@Test
public void tests036_IsElementPresent() throws Exception {
// Open the link
webDriver.get(baseUrl);
// Maximize browser window
webDriver.manage().window().maximize();
//
if (webDriver.findElement(By.id("verifybutton")) != null) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}
}
@AfterMethod
public void shutDown() throws Exception {
// This will close the browser
webDriver.quit();
}
}