Guest User

Untitled

a guest
Apr 2nd, 2019
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.openqa.selenium.By;
  2. import org.openqa.selenium.WebDriver;
  3. import org.openqa.selenium.chrome.ChromeDriver;
  4. import org.openqa.selenium.*;
  5.  
  6. public class Form {
  7. public static void main(String[] args) {
  8.  
  9. // declaration and instantiation of objects/variables
  10. System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
  11. WebDriver driver = new ChromeDriver();
  12.  
  13. String baseUrl = "http://demo.guru99.com/test/login.html";
  14. driver.get(baseUrl);
  15.  
  16. // Get the WebElement corresponding to the Email Address(TextField)
  17. WebElement email = driver.findElement(By.id("email"));
  18.  
  19. // Get the WebElement corresponding to the Password Field
  20. WebElement password = driver.findElement(By.name("passwd"));
  21.  
  22. email.sendKeys("abcd@gmail.com");
  23. password.sendKeys("abcdefghlkjl");
  24. System.out.println("Text Field Set");
  25.  
  26. // Deleting values in the text box
  27. email.clear();
  28. password.clear();
  29. System.out.println("Text Field Cleared");
  30.  
  31. // Find the submit button
  32. WebElement login = driver.findElement(By.id("SubmitLogin"));
  33.  
  34. // Using click method to submit form
  35. email.sendKeys("abcd@gmail.com");
  36. password.sendKeys("abcdefghlkjl");
  37. login.click();
  38. System.out.println("Login Done with Click");
  39.  
  40. //using submit method to submit the form. Submit used on password field
  41. driver.get(baseUrl);
  42. driver.findElement(By.id("email")).sendKeys("abcd@gmail.com");
  43. driver.findElement(By.name("passwd")).sendKeys("abcdefghlkjl");
  44. driver.findElement(By.id("SubmitLogin")).submit();
  45. System.out.println("Login Done with Submit");
  46.  
  47. //driver.close();
  48.  
  49. }
  50. }
RAW Paste Data