Example of Selenium Webdriver Script

Please find the following example Selenium scripts for automated website testing 

Example:
 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
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class DemoScript {

 public static void main(String[] args) {

  // TODO Auto-generated method stub
  System.setProperty("webdriver.gecko.driver", "./MyProject/driver/geckodriver.exe");
  WebDriver driver = new FirefoxDriver();
  driver.get("https://www.facebook.com/");

  // Get current URL
  String URL = driver.getCurrentUrl();
  System.out.println("Current URL is  : " + URL);

  // Check if the webelement 'Email or Phone' is enabled or not
  boolean checkExist = driver.findElement(By.id("email")).isEnabled();
  System.out.println(checkExist);

  // Locating and entering value in the text box
  WebElement email = driver.findElement(By.id("email"));
  email.sendKeys("ABCD@gmail.com");

  // get the email id entered by user from text box
  String email_id = driver.findElement(By.id("email")).getAttribute("value");
  System.out.println("The email entered by user is  : " + email_id);

  // click on hyperlink Forgotten account?
  driver.findElement(By.linkText("Forgotten account?")).click();

 }
}


<-- Previous || Next -->

No comments:

Post a Comment