Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import org.testng.annotations.BeforeClass;
- import org.testng.annotations.Test;
- import java.nio.file.Paths;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.support.ui.ExpectedCondition;
- import org.openqa.selenium.support.ui.WebDriverWait;
- public class BasicSeleniumTestNGTest {
- @BeforeClass
- public static void setUpClass() throws Exception {
- // Proper version of geckodriver can be downloaded from here:
- // https://github.com/mozilla/geckodriver/releases
- final String pathToGeckoDriver = Paths.get("/Users/sammers/Downloads/chromedriver")
- .toAbsolutePath().toString();
- System.setProperty("webdriver.chrome.driver", pathToGeckoDriver);
- }
- @Test
- public void testMain() throws Exception {
- // Create a new instance of the Firefox driver
- // Notice that the remainder of the code relies on the interface,
- // not the implementation.
- final WebDriver driver = new ChromeDriver();
- // And now use this to visit Google
- driver.get("http://xe.com/");
- // Alternatively the same thing can be done like this
- // driver.navigate().to("http://www.google.com");
- // Find the text input element by its name
- final WebElement element = driver.findElement(By.name("Amount"));
- // Enter something to search for
- element.sendKeys("50");
- // Now submit the form. WebDriver will find the form for us from the element
- element.submit();
- final WebElement elementResult = driver.findElement(By.xpath("//span[contains(@class, 'uccResultAmount')]"));
- System.out.println(elementResult.getText());
- //Close the browser
- driver.quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement