0% found this document useful (0 votes)
35 views5 pages

2-6 STQA Prac

Uploaded by

Firoza
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)
35 views5 pages

2-6 STQA Prac

Uploaded by

Firoza
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/ 5

Practical No.

11

Handling Alerts using selenium web driver

Aim: To Demonstrate different types of alerts

Source Code:

package firstDay;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class DemoAlert {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver","C:\\Users\\Shreeja\\Desktop\\Software Testing
Files\\chromedriver.exe");
WebDriver wd = new ChromeDriver();
wd.get("http://frontaccounting.squadinfotech.in/index.php");
wd.findElement(By.name("user_name_entry_field")).sendKeys("frontuser1");
wd.findElement(By.name("password")).sendKeys("frontuser1");
Select s = new Select(wd.findElement(By.name("company_login_name")));
s.selectByVisibleText("Squad_MT_OL_48");
wd.findElement(By.name("SubmitUser")).click();
wd.findElement(By.linkText("Direct Delivery")).click();
wd.findElement(By.id("CancelOrder")).click();
Thread.sleep(2000);
Alert alt = wd.switchTo().alert();
System.out.println("Text of Alert " + alt.getText());//capture text
alt.accept();//click on OK button
// alt.dismiss(); click on cancel button
}
}

Prof. Nitesh Kumar


OUTPUT :-

Prof. Nitesh Kumar


Practical No. 12

Handling different Web elements

Aim: To Demonstrate Handling dropdown

Source Code:

package firstDay;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class DemoDropDown {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\Shreeja\\Desktop\\Software Testing
Files\\chromedriver.exe");
WebDriver wd = new ChromeDriver();
wd.get("https://blazedemo.com/");
Select s = new Select(wd.findElement(By.name("fromPort")));
s.selectByIndex(1);
s.selectByValue("Boston");
s.selectByVisibleText("San Diego");
}
}

OUTPUT :-

Prof. Nitesh Kumar


Practical No. 13

Handling different web elements

Aim: To Demonstrate Handling listbox

Source Code:
package firstDay;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class DemoMultiSelect {

public static void main(String[] args) throws Exception {


System.setProperty("webdriver.chrome.driver","C:\\Users\\Shreeja\\Desktop\\chromedriver.exe");
WebDriver wd = new ChromeDriver();
wd.get("file:///C:\\Users\\Shreeja\\Desktop\\MultiSelect.html");

Select s = new Select(wd.findElement(By.id("cars")));


if(s.isMultiple())
{
s.selectByIndex(1);
//s.selectByValue("3");
//s.selectByVisibleText("Ferrari");

Thread.sleep(2000);
//s.deselectByIndex(1);
//s.deselectAll();
}
}

OUTPUT :-

Prof. Nitesh Kumar


Practical No. 14

Handling different web elements

Aim: To Demonstrate Handling radiobutton

Source Code:
package firstDay;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class DemoRadio {


public static void main(String[] args)
System.setProperty("webdriver.chrome.driver","C:\\Users\\Shreeja\\Desktop\\chromedriver.exe");
WebDriver wd = new ChromeDriver();
wd.get("file:///C:/Users/Shreeja/Desktop/radio.html");
wd.findElement(By.xpath("//*[@id=\"female\"]")).click();
}
}

OUTPUT :-

Prof. Nitesh Kumar

You might also like