0% found this document useful (0 votes)
59 views6 pages

20mis1080 Lab11

This document contains code examples for using Selenium WebDriver with Java to automate tests on web applications. It includes examples of finding elements by ID, name, XPath, interacting with dropdown menus, and using get() and getText() methods. The code examples demonstrate automating actions like entering text, clicking buttons, and retrieving page titles on websites like Facebook and Google.

Uploaded by

Gaganya Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views6 pages

20mis1080 Lab11

This document contains code examples for using Selenium WebDriver with Java to automate tests on web applications. It includes examples of finding elements by ID, name, XPath, interacting with dropdown menus, and using get() and getText() methods. The code examples demonstrate automating actions like entering text, clicking buttons, and retrieving page titles on websites like Facebook and Google.

Uploaded by

Gaganya Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ASSIGNMENT-11

A2 SLOT

Course Program: Int. M. Tech

Course code: SWE-3006

Course Title: Advance Software Testing

Batch:2020-2025

Submitted to

Dr.Umamaheswari E

Submitted by
Sathish Kumar V- 20MIS1080
VTOP Login:

CODE:

package lab11;

import org.openqa.selenium.By;

import org.openqa.selenium.firefox.FirefoxDriver;

public class test {

public static void main(String[] args)

{
System.setProperty("webdriver.gecko.driver","C:\\Users\\sathi\\Downloads\\geckodriver-
v0.33.0-win64\\geckodriver.exe");

// FirefoxOptions options = new FirefoxOptions();

FirefoxDriver driver= new FirefoxDriver();

driver.get("https://vtopcc.vit.ac.in/vtop/login");

driver.findElement(By.name("username")).sendKeys("20MIS1080");

driver.findElement(By.id("password")).sendKeys("vit");

driver.findElement(By.id("submitBtn")).click();

driver.quit();

}
Example ( for id and name):

import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
public class firstlastest {
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver","E:\\gecko\\geckodriver.e
xe");

// FirefoxOptions options = new FirefoxOptions();


FirefoxDriver driver= new FirefoxDriver();
driver.get("https://www.facebook.com");
driver.findElement(By.id("email")).sendKeys("Advance Software
testing");
driver.findElement(By.name("pass")).sendKeys("vit");
driver.findElement(By.name("login")).click();
driver.quit();
}

Example xpath

import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;

public class xpath {


public static void main(String[] args)
{

System.setProperty("webdriver.gecko.driver","E:\\gecko\\geckodriver.e
xe");
// FirefoxOptions options = new FirefoxOptions();
FirefoxDriver driver= new FirefoxDriver();

driver.get("https://www.google.com");

driver.findElement(By.xpath("//*[@id=\"APjFqb\"]")).sendKeys("vit");

driver.findElement(By.xpath("/html/body/div[1]/div[3]/form/div[1]/div[1]/di
v[4]/center/input[1]")).click();
driver.quit();
}
}

Example – drop down menu

package latestversion;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class drop {


public static void main(String[] args)
{

System.setProperty("webdriver.gecko.driver","E:\\gecko\\geckodriver.e
xe");

// FirefoxOptions options = new FirefoxOptions();


FirefoxDriver driver= new FirefoxDriver();

driver.get("https://www.facebook.com/register");
Select drop1 = new
Select(driver.findElement(By.id("month")));
Select drop2= new
Select(driver.findElement(By.id("day")));
drop2.selectByIndex(3);
drop1.selectByVisibleText("Mar");

driver.quit();
}

Example –get() & getText()

package lab11;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class title {
public static void main(String[] args)
{

System.setProperty("webdriver.gecko.driver","C:\\Users\\sathi\\Downloads\\geckodri
ver-v0.33.0-win64\\geckodriver.exe");
// FirefoxOptions options = new FirefoxOptions();
FirefoxDriver driver= new FirefoxDriver();
driver.get("https://www.facebook.com");
System.out.println("Page title is : " + driver.getTitle());
WebElement element1=driver.findElement(By.name("login"));
System.out.println("button text is : " + element1.getText());
driver.quit();
}
}

You might also like