Selenium Automation Lab Programs 3-8 (6 Programs)
Selenium Automation Lab Programs 3-8 (6 Programs)
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
}
Lab Exercise 4 – Program to verify whether a test case
passed / failed
package webdrivercommand;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
//import jxl.write.Label;
System.setProperty("webdriver.chrome.driver","C://Sel
enium//chromedriver.exe");
WebDriver driver=new ChromeDriver();
//To navigate to URL
driver.get("http://www.way2sms.com/");
Thread.sleep(5000);
driver.findElement(By.id("mobileNo")).sendKeys("97003
39582");
Thread.sleep(5000);
driver.findElement(By.name("password")).sendKeys("han
uman");
Thread.sleep(5000);
driver.findElement(By.xpath("//b[@id='mainErr']/follo
wing::*[5]")).click();
Thread.sleep(5000);
//Verification Point
String o="http://www.way2sms.com/send-sms";
String z=driver.getCurrentUrl();
if(z.equals(o))
{
System.out.println("Login Sucessful_Test
Passed");
}
else
{
System.out.println("Login
UnSucessful_TestFailed");
}
//Close Site
driver.close();
}
}
Lab Exercise 5 – Program to display the count of the
total number of web hyperlinks on a webpage and
listing them in order
package webdrivercommand;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
driver.get("http://demo.guru99.com/test/newtours//");
Thread.sleep(5000);
List<WebElement> e =
driver.findElements(By.tagName("a"));
System.out.println(e.size());
for(int i=0; i<e.size(); i=i+1){
System.out.println(e.get(i).getText());
}
driver.close();
}}
Lab Exercise 6 – Program to display the total number of
elements in a combo box
package webdrivercommand;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class Totalnoofobjectscombobox {
public static void main(String[] args) throws
InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","C://Sel
enium//chromedriver.exe");
WebDriver driver=new ChromeDriver();
//To navigate to URL
driver.get("http://demo.guru99.com/test/newtours//");
Thread.sleep(5000);
//Syntax:
//objectName.Method(StaticClass.Locator(
"value")).OperationMethod();
//Click on Register Link
driver.findElement(By.linkText("REGISTER")).click();
Thread.sleep(5000);
//Pass text into Textbox for FirstName
driver.findElement(By.name("firstName")).sendKeys("Ma
dhwaraj");
Thread.sleep(5000);
driver.findElement(By.name("lastName")).sendKeys("Pro
f");
Thread.sleep(5000);
driver.findElement(By.name("phone")).sendKeys("970333
6699");
Thread.sleep(5000);
driver.findElement(By.id("userName")).sendKeys("abcd@
gmail.com");
Thread.sleep(5000);
driver.findElement(By.name("address1")).sendKeys("che
nnai fasf");
Thread.sleep(5000);
//driver.findElement(By.name("address2")).sen
dKeys("chennai fasf");
//Thread.sleep(5000);
driver.findElement(By.name("city")).sendKeys("chennai
");
Thread.sleep(5000);
driver.findElement(By.name("state")).sendKeys("TN");
Thread.sleep(5000);
driver.findElement(By.name("postalCode")).sendKeys("5
000221");
Thread.sleep(5000);
//selectByIndex();
//selectByVisibleText("INDIA");
s.selectByVisibleText("INDIA");
Thread.sleep(5000);
driver.findElement(By.id("email")).sendKeys("abcd@gma
il.com");
Thread.sleep(5000);
driver.findElement(By.name("password")).sendKeys("Mad
hvaraj");
Thread.sleep(5000);
driver.findElement(By.name("confirmPassword")).sendKe
ys("Madhvaraj");
Thread.sleep(5000);
//Image Button
//driver.findElement(By.name("Submit")).click
();
//Thread.sleep(5000);
//close browser
driver.close();
}
Lab Exercise 7 – Program to automate the switching
between two websites and performing some actions
with them, displaying the actions using Mozilla web
browser
package webdrivercommand;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
System.setProperty("webdriver.chrome.driver","C://Sel
enium//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.navigate().to("https://seleniummaster.com/llc/
");
String toURL=driver.getCurrentUrl();
System.out.println(toURL);
Thread.sleep(5000);
driver.navigate().back();
String backURL=driver.getCurrentUrl();
System.out.println(backURL);
Thread.sleep(5000);
driver.navigate().refresh();
String refreshURL=driver.getCurrentUrl();
System.out.println(refreshURL);
Thread.sleep(5000);
driver.navigate().to("https://seleniummaster.com/llc/
");
String toURL1=driver.getCurrentUrl();
System.out.println(toURL1);
Thread.sleep(5000);
//Maximize Window
Thread.sleep(5000);
driver.close();
}
Lab Exercise 8 – Program to automate the reading of
data from an excel file and displaying the data on the
eclipse console output window
package webdrivercommand;
import java.io.FileInputStream;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;