Guest User

Untitled

a guest
Jul 18th, 2017
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. package com;
  2.  
  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.WebElement;
  6. import org.openqa.selenium.firefox.FirefoxDriver;
  7.  
  8. public class MercuryToursLogin {
  9.  
  10.     /**
  11.      * @param args
  12.      * @throws InterruptedException
  13.      */
  14.     public static void main(String[] args) throws InterruptedException {
  15.          // Create a new instance of the Firefox driver
  16.         // Notice that the remainder of the code relies on the interface,
  17.         // not the implementation.
  18.         System.setProperty("webdriver.gecko.driver", "C:\\\\geckodriver\\geckodriver.exe");
  19.         WebDriver driver = new FirefoxDriver();
  20.        
  21.         String baseURL = "http://newtours.demoaut.com/";
  22.         // Open browser using the defined base URL
  23.         driver.get(baseURL);
  24.        
  25.         // Print out the title of the page. Should be "About us | Demoqa"
  26.         System.out.println("Page title before is: " + driver.getTitle());
  27.        
  28.         // Find the text input element by its name
  29.         WebElement user = driver.findElement(By.name("userName"));
  30.         WebElement pass = driver.findElement(By.name("password")); 
  31.         WebElement login = driver.findElement(By.name("login"));       
  32.  
  33.         user.sendKeys("tutorial");
  34.         Thread.sleep(1000);
  35.         pass.sendKeys("tutorial");
  36.         Thread.sleep(1000);
  37.        
  38.         // Click on the About Us link
  39.         login.click(); 
  40.        
  41. //        WebElement findFlight = driver.findElement(By.tagName(""));
  42. //      WebElement findFlight = driver.getPageSource().contains("Flight Details");
  43. //      String xpath = "html body div table tbody tr td table tbody tr td table tbody tr td table tbody tr td img";
  44.         Thread.sleep(5000);
  45.         String title = driver.getTitle();
  46.         System.out.println("the title after login->> "+title);
  47. //      if(driver.getPageSource().contains("Flight Finder")){
  48. //          System.out.println("pass");
  49. //      }else{
  50. //          System.out.println("fail");
  51. //      }
  52.                  
  53.                  
  54.         //Close the browser
  55.         driver.quit();
  56.     }
  57.  
  58. }
Add Comment
Please, Sign In to add comment