0% found this document useful (0 votes)
17 views

Stqa Practicalno 8

This Java code demonstrates various Selenium WebDriver functions using different elements on test webpages. It logs in to a test account, selects radio buttons and checkboxes, and verifies the status of a persistent checkbox over multiple page loads. The code finds elements by ID, sends keys to fill text fields, clicks buttons, and checks if elements are selected. It tests functions like sendKeys, click, submit, clear, isSelected, and getting/closing the WebDriver on different test pages.

Uploaded by

vaibhav gaikwad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Stqa Practicalno 8

This Java code demonstrates various Selenium WebDriver functions using different elements on test webpages. It logs in to a test account, selects radio buttons and checkboxes, and verifies the status of a persistent checkbox over multiple page loads. The code finds elements by ID, sends keys to fill text fields, clicks buttons, and checks if elements are selected. It tests functions like sendKeys, click, submit, clear, isSelected, and getting/closing the WebDriver on different test pages.

Uploaded by

vaibhav gaikwad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

STQA Practical no 8

~Made by Shlok Punekar


Code:
package prac8;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.*;

public class practicalno8 {


public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Administrator\\Downloads\\
chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "http://demo.guru99.com/test/login.html";
driver.get(baseUrl);
WebElement email = driver.findElement(By.id("email"));
WebElement password = driver.findElement(By.id("passwd"));
email.sendKeys("[email protected]");
password.sendKeys("gongonegoner");
System.out.println("TextField Set");

email.clear();
password.clear();
System.out.println("Text Field Cleared");

WebElement login = driver.findElement(By.id("SubmitLogin"));


email.sendKeys("[email protected]");
password.sendKeys("gongonegoner");
login.click();

System.out.println("Login done with click");


driver.get(baseUrl);

driver.findElement(By.id("email")).sendKeys("[email protected]");
driver.findElement(By.id("passwd")).sendKeys("gongonegoner");
driver.findElement(By.id("SubmitLogin")).submit();
System.out.println("login done with Submit fucntion");

driver.get("http://demo.guru99.com/test/radio.html");
WebElement rad1 = driver.findElement(By.id("vfb-7-1"));
rad1.click();
System.out.println("Radio Button 1 Selected");
WebElement rad2 = driver.findElement(By.id("vfb-7-2"));
rad1.click();
System.out.println("Radio Button 2 Selected");

WebElement check = driver.findElement(By.id("vfb-6-0"));


check.click();

if (check.isSelected()) {
System.out.println("CheckBox is toggled on.");
}
else {
System.out.println("CheckBox is toggled off");
}

driver.get("http://demo.guru99.com/test/facebook.html");
WebElement persist = driver.findElement(By.id("persist_box"));

for(int i=0;i<2;i++) {
persist.click();
System.out.println("Facebook Persists CheckBox Status is - "+persist.isSelected());
}
driver.close();
}

You might also like