Selenium Record
Selenium Record
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.chrome.ChromeDriver;
System.setProperty("webdriver.chrome.driver","D:\\2013712080010\\selenium
driver\\chromedriver_win32_94\\chromedriver.exe");
driver.get(baseUrl);
actualTitle = driver.getTitle();
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
driver.close();
HTML CODE:
<html>
<head>
<title>
My First Selenium
</title>
</head>
<body>
<h1>this is my First Selenium page</h1>
</body>
</html>
OUTPUT:
JAVA CODE:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;
driver.get("d:\\gcd.html");
driver.manage().window().maximize();
tn1.sendKeys("10");
tn2.sendKeys("12");
login.click();
<html>
<head>
<script type="text/javascript">
function gcd()
{
var x,y;
x=parseInt(document.myform.n1.value);
y=parseInt(document.myform.n2.value);
while (x!=y)
{
if (x>y)
x=x-y;
else
y=y-x;
}
document.myform.result.value=x;
}
</script>
</head>
<body>
<h1 align="center"> Program to calculate gcd of two numbers </h1>
<hr color="red">
<center>
Enter two numbers :
<form name="myform">
Number 1 :<input type="text" name="n1" value=""><br><br>
Number 2 :<input type="text" name="n2" value=""><br><br>
<input type="button" id="submit" value="Get GCD" onClick="gcd()">
<br><br> GCD is :<input type="text" id="result" value="">
</form>
</body>
</html>
OUTPUT:
JAVA CODE:
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
importorg.openqa.selenium.*;
publicclass Program2 {
publicstaticvoidmain(String[] args) {
System.setProperty("webdriver.chrome.driver","D:\\2013712080010\\selenium
driver\\chromedriver_win32_94\\chromedriver.exe");
WebDriver driver = newChromeDriver();
driver.get("d:\\loginpage.html");
driver.manage().window().maximize();
WebElementtn1 = driver.findElement(By.name("uname"));
WebElementtn2 = driver.findElement(By.name("pwd"));
tn1.sendKeys("mscit");
tn2.sendKeys("pwd");
WebElementlogin = driver.findElement(By.id("submit"));
login.click();
String tresult = driver.findElement(By.id("result")).getAttribute("value");
}
HTML CODE:
<html>
<head>
script type="text/javascript">
function chk()
{
var x,y;
x=document.myform.uname.value;
y=document.myform.pwd.value;
if (x=="mscit" && y=="pwd")
document.myform.result.value="Login Success";
else
document.myform.result.value="Login Fail";
}
</script>
</head>
<body>
<h1 align="center"> User Login Page </h1>
<hr color="red">
<center>
<form name="myform">
User Name :<input type="text" name="uname" value=""><br><br>
Password :<input type="text" name="pwd" value=""><br><br>
<input type="button" id="submit" value="Login" onClick="chk()">
<br><br>Status :<input type="text" id="result" value="">
</form>
</body>
</html>
OUTPUT:
JAVA CODE:
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileOutputStream;
importorg.apache.poi.xssf.usermodel.XSSFSheet;
importorg.apache.poi.xssf.usermodel.XSSFWorkbook;
publicclass Program4 {
publicstaticvoidmain(String[] args) {
// TODO Auto-generated method stub
try {
XSSFWorkbookwb=newXSSFWorkbook(fis);
XSSFSheetsh1= wb.getSheetAt(0);
System.out.println(sh1.getRow(0).getCell(0).getStringCellValue());
System.out.println(sh1.getRow(0).getCell(1).getStringCellValue());
System.out.println(sh1.getRow(1).getCell(0).getStringCellValue());
System.out.println(sh1.getRow(1).getCell(1).getStringCellValue());
System.out.println(sh1.getRow(2).getCell(0).getStringCellValue());
System.out.println(sh1.getRow(2).getCell(1).getStringCellValue());
sh1.getRow(0).createCell(2).setCellValue("DEPT");
sh1.getRow(1).createCell(2).setCellValue("SALES");
sh1.getRow(2).createCell(2).setCellValue("MKTG");
FileOutputStreamfout=newFileOutputStream(new File("d:\\test.xlsx"));
wb.write(fout);
fout.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
OUTPUT:
JAVA CODE:
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;
System.setProperty("webdriver.chrome.driver","D:/chromedriver.exe");
driver.get("D:/objects.html");
List<WebElement>allElements = driver.findElements(By.xpath("//*"));
}
HTML CODE:
<html>
<select id="fruits">
<option> Apple</option>
</body>
</html>
OUTPUT:
JAVA CODE:
importjava.util.List;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.chrome.ChromeDriver;
importorg.openqa.selenium.support.ui.Select;
publicclass Program6 {
publicstaticvoidmain(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","D:\\2013712080010\\selenium
driver\\chromedriver_win32_94\\chromedriver.exe");
driver.get("d:\\selenium2.html");
WebElementselectElement = driver.findElement(By.id("fruits"));
Select listBox = new Select(selectElement);
intsize1 = listBox.getOptions().size();
}
HTML CODE:
<html>
<head><title>My First Selenium</title></head>
<body><h1> Selenium is open source testing tool </h1>
<a href="first.html"> Category I </a>
<a href="second.html"> Category II </a>
<a href="Third.html"> Category III </a>
<input type="text" > Enter Name </input>
<select id="fruits">
<option> Mango </option>
<option> Apple</option>
<option> Grapes </option>
<option> Guava </option>
OUTPUT:
JAVA CODE:
packageMypackage;
importjava.io.*;
publicclass prac7 {
publicstaticvoidmain(String[] args) {
try {
Runtime.getRuntime().exec("wscript C:/Users/Lab1sys01/Desktop/countdesk.vbs");
}
catch (IOExceptione) {
System.exit(0);
}
}
countdesk.vbs
Dim fso, DesktopPath
set fso = CreateObject("Scripting.FileSystemObject")
DesktopPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") 'Files count
MsgBox("The number of files on the desktop is : " &fso.GetFolder(DesktopPath).Files.Count) 'Folders count
MsgBox("The number of folders on the desktop is : " &fso.GetFolder(DesktopPath).SubFolders.Count)
OUTPUT
JAVA CODE:
importjava.util.List;
importjava.util.concurrent.TimeUnit;
importorg.openqa.selenium.By;
importorg.openqa.selenium.WebElement;
importorg.openqa.selenium.WebDriver;
importorg.openqa.selenium.chrome.ChromeDriver;
publicclass checkbox {
publicstaticvoidmain(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver","D:/chromedriver.exe");
WebDriver driver = newChromeDriver();
String baseUrl = "D:/checkbox.html";
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get(baseUrl);
List<WebElement>checkBoxes =
driver.findElements(By.xpath("//input[@type='Checkbox']"));
intcheckedCount=0, uncheckedCount=0;
for(inti=0; i<checkBoxes.size(); i++){
System.out.println(i+" checkbox is selected "+checkBoxes.get(i).isSelected());
if(checkBoxes.get(i).isSelected()){
checkedCount++;
}else{
uncheckedCount++;
}
}
System.out.println("number of selected checkbox: "+checkedCount);
System.out.println("number of unselected checkbox: "+uncheckedCount);
}}
HTML CODE:
<html>
<body>
<input type="Checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="Checkbox" id="vehicle2" name="vehicle2" checked="checked" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="Checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label><br>
</body>
</html>
OUTPUT: