forked from Sonal0409/8PMJulyBatchJava-SeleniumPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlertBoxDemo.java
More file actions
64 lines (30 loc) · 1.53 KB
/
AlertBoxDemo.java
File metadata and controls
64 lines (30 loc) · 1.53 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package seleniumScripts;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class AlertBoxDemo {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Users\\vishal mittal\\Downloads\\chromedriver_win32 (12)\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize(); // maximize the browser window
driver.manage().deleteAllCookies(); // delete cookies on the browser
driver.get("https://register.rediff.com/register/register.php?FormName=user_details");
// inspecting username textbox and entering data
driver.findElement(By.xpath("//*[@id=\"tblcrtac\"]/tbody/tr[3]/td[3]/input")).sendKeys("Sonalmittal");
// click on create account button
driver.findElement(By.xpath("//*[@id=\"Register\"]")).click();
Thread.sleep(3000);
// Switch from window to Alert box
// Alert class have methods like accept(), dismiss(), getText(), sendKeys()
Alert a= driver.switchTo().alert();
Thread.sleep(2000);
String text= a.getText();
System.out.println(text);
Thread.sleep(2000);
a.accept();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[@id=\"tblcrtac\"]/tbody/tr[7]/td[3]/input[1]")).sendKeys("sonal04");
}
}