What is Selenium
Selenium is one of the most widely used open source Web UI (User Interface) automation
testing suite.
It was originally developed by Jason Huggins in 2004 as an internal tool at Thought Works.
Selenium supports automation across different browsers, platforms and programming
languages.
Web resources
https://www.javatpoint.com/selenium-tutorial
What is automation
Automation is the use of machines or technology to perform tasks without much
human intervention.
Eg:
Filling form data
Clicking on buttons
What is web driver?
A WebDriver is a browser automation framework. It accepts commands and sends them
to a browser. WebDriver in Selenium was created by Simon Stewart in 2006. It was the first
cross-platform testing framework that could control the browser from the level of the
operating system.
SOURCE CODE TO OPEN “GOOGLE” USING SELENIUM JAVA CODE
package svce;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
class openedge
{
public static void main(String args[])
{
System.setProperty(
"webdriver.edge.driver",
"C:\\Users\\SVCE\\Downloads\\msedgedriver.exe");
// Instantiate a EdgeDriver class.
WebDriver driver = new EdgeDriver();
// Launch Website
driver.get("https://www.google.co.in/");
}
}
_______________________________________________________
SOURCE CODE to open a “form.html” file on ur desktop and filling it automatically
form.html(save it on desktop)
—-----------
<html>
<head>
<style>
form
{
width:50%;
margin-left:100px;
}
input,label
{
margin-left:50px;
}
h1
{
color:magenta;
}
</style>
</head>
<body>
<script>
var mymail="[email protected]";
var mypass="cse123";
function show()
{
var fmail=document.getElementById("mail").value;
var fpass=document.getElementById("pass").value;
if(mymail==fmail)
{
if(mypass==fpass)
{
document.write("<center><h1>welcome,valid
user</h1></center>");
}
else
{
document.write("<center><h1>your password is not
correct</h1></center>");
}
}
else
{
if(mypass!=fpass)
{
document.write("<center><h1>both email and passwords are
wrong</h1></center>");
}
else
{
document.write("<center><h1>your e-mail is not
correct</h1></center>");
}
}
}
</script>
<form>
<fieldset>
<legend><h1>Fill the data</h1></legend>
<label>Email:</label><br>
<input type="text" id="mail"><br><br>
<label>password:</label><br>
<input type="password" id="pass"><br><br>
<input type="button" name="mybut" value="submit" onclick=show()>
</fieldset>
</form>
</body>
</html>
___________
autofill.java(enter this code in “eclipse” IDE)
—------------
//version 1
package svce;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
class autofill
{
public static void main(String args[])throws Exception
{
System.setProperty(
"webdriver.edge.driver",
"C:\\Users\\SVCE\\Downloads\\msedgedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new EdgeDriver();
// Launch Gmail login page
driver.navigate().to("C:/Users/SVCE/Desktop/form.html");
// Click on the search text box and send value
Thread.sleep(5000);
driver.findElement(By.id("mail")).sendKeys("
[email protected]");
Thread.sleep(5000);
driver.findElement(By.id("pass")).sendKeys("cse123");
// Click on the search button
Thread.sleep(5000);
driver.findElement(By.name("mybut")).click();
}
}
__________________________________________________________________
//version 2
package svce;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
class sel
{
public static void main(String args[])throws Exception
{
System.setProperty(
"webdriver.edge.driver",
"C:\\Users\\SVCE\\Downloads\\msedgedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new EdgeDriver();
// Launch Gmail login page
String mails[]=
{"[email protected]","[email protected]","[email protected]"};
String pass[]= {"cse121","cse122","cse123"};
driver.navigate().to("C:/Users/SVCE/Desktop/form.html");
// Click on the search text box and send value
for(int i=0;i<mails.length;i++)
{
Thread.sleep(3000);
driver.findElement(By.id("mail")).sendKeys(mails[i]);
Thread.sleep(3000);
driver.findElement(By.id("pass")).sendKeys(pass[i]);
// Click on the search button
Thread.sleep(3000);
driver.findElement(By.name("mybut")).click();
Thread.sleep(3000);
driver.navigate().refresh();
}
//close the browser window
driver.close();
}
}
__________________________________________________________________
Login to your “gmail account automatically” using selenium java program
package nathpro;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
class demo
{
public static void main(String args[])throws Exception
{
System.setProperty(
"webdriver.edge.driver",
"C:\\Users\\SVCE\\Downloads\\msedgedriver.exe");
// Instantiate a ChromeDriver class.
WebDriver driver = new EdgeDriver();
// Launch Gmail login page
driver.navigate().to("https://mail.google.com/");
// Click on the search text box and send value
Thread.sleep(5000);
driver.findElement(By.id("identifierId")).sendKeys("[email protected]
n");
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id=\"identifierNext\"]/div")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id=\"password\"]/div[1]/div/div[1]/input"
)).sendKeys("may26#1989");
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id=\"passwordNext\"]/div/button/span")
).click();
}
}