-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet_Data
71 lines (47 loc) · 1.91 KB
/
Get_Data
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
65
66
67
68
69
70
71
package automationframework;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Get_Data {
public static void main(String[] args) {
//Setting the driver path
System.setProperty("webdriver.chrome.driver", "/Users/stacysargam/Documents/Selenium/chromedriver-mac-x64/chromedriver");
//Creating WebDriver instance
WebDriver driver = new ChromeDriver();
//Navigate to web page
driver.get("https://demoqa.com/login");
//Maximizing window
driver.manage().window().maximize();
//Retrieving web page title
String title = driver.getTitle();
System.out.println("The page title is : " +title);
int titlelength = driver.getTitle().length();
System.out.println("Length of the page title is:" +titlelength);
String CurrentUrl = driver.getCurrentUrl();
System.out.println("URL of the site is: "+CurrentUrl);
//Locating web element
WebElement uName = driver.findElement(By.xpath("//*[@id='userName']"));
WebElement pswd = driver.findElement(By.xpath("//*[@id='password']"));
WebElement loginBtn = driver.findElement(By.xpath("//*[@id='login']"));
//Peforming actions on web elements
uName.sendKeys("testuser");
pswd.sendKeys("Password@123");
loginBtn.click();
try {
//Locating web element
WebElement logoutBtn = driver.findElement(By.xpath("//div[@class='text-right col-md-5 col-sm-12']//button[@id='submit']"));
//Validating presence of element
if(logoutBtn.isDisplayed()){
//Performing action on web element
logoutBtn.click();
System.out.println("LogOut Successful!");
}
}
catch (Exception e) {
System.out.println("Incorrect login....");
}
//Closing browser session
driver.close();
}
}