Advertisement
Guest User

Untitled

a guest
Nov 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. package com.company;
  2.  
  3. import org.testng.annotations.BeforeClass;
  4. import org.testng.annotations.Test;
  5.  
  6. import java.nio.file.Paths;
  7.  
  8. import org.openqa.selenium.By;
  9. import org.openqa.selenium.WebDriver;
  10. import org.openqa.selenium.WebElement;
  11. import org.openqa.selenium.firefox.FirefoxDriver;
  12. import org.openqa.selenium.chrome.ChromeDriver;
  13. import org.openqa.selenium.support.ui.ExpectedCondition;
  14. import org.openqa.selenium.support.ui.WebDriverWait;
  15.  
  16. public class BasicSeleniumTestNGTest {
  17.     @BeforeClass
  18.     public static void setUpClass() throws Exception {
  19.         // Proper version of geckodriver can be downloaded from here:
  20.         // https://github.com/mozilla/geckodriver/releases
  21.         final String pathToGeckoDriver = Paths.get("/Users/sammers/Downloads/chromedriver")
  22.                 .toAbsolutePath().toString();
  23.         System.setProperty("webdriver.chrome.driver", pathToGeckoDriver);
  24.     }
  25.  
  26.     @Test
  27.     public void testMain() throws Exception {
  28.         // Create a new instance of the Firefox driver
  29.         // Notice that the remainder of the code relies on the interface,
  30.         // not the implementation.
  31.         final WebDriver driver = new ChromeDriver();
  32.  
  33.         // And now use this to visit Google
  34.         driver.get("http://xe.com/");
  35.         // Alternatively the same thing can be done like this
  36.         // driver.navigate().to("http://www.google.com");
  37.  
  38.         // Find the text input element by its name
  39.         final WebElement element = driver.findElement(By.name("Amount"));
  40.  
  41.         // Enter something to search for
  42.         element.sendKeys("50");
  43.  
  44.         // Now submit the form. WebDriver will find the form for us from the element
  45.         element.submit();
  46.        
  47.         final WebElement elementResult = driver.findElement(By.xpath("//span[contains(@class, 'uccResultAmount')]"));
  48.         System.out.println(elementResult.getText());
  49.         //Close the browser
  50.         driver.quit();
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement