-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment6.java
50 lines (33 loc) · 1.57 KB
/
Assignment6.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
public class Assignment6 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "/Users/tanvi/Documents/automation_testing/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://rahulshettyacademy.com/AutomationPractice/");
// select a checkbox
WebElement optionSelected = driver.findElement(By.id("checkBoxOption2"));
optionSelected.click();
// get the title of selected checkbox
String labelSelected = driver.findElement(By.xpath("//div[@id='checkbox-example']/fieldset/label[2]")).getText();
System.out.println(labelSelected);
// choose the label selected in dropdown
//driver.findElement(By.id("dropdown-class-example")).click();
Select dropDown = new Select(driver.findElement(By.id("dropdown-class-example")));
dropDown.selectByVisibleText(labelSelected);
// add gthe selected label to alert box
driver.findElement(By.id("name")).sendKeys(labelSelected);
driver.findElement(By.id("alertbtn")).click();
String alertMessage = driver.switchTo().alert().getText();
System.out.println(alertMessage);
driver.switchTo().alert().accept();
//if(alertMessage.contains(labelSelected))
// System.out.println("Alert contains " + labelSelected);
Assert.assertTrue(alertMessage.contains(labelSelected));
}
}