/**
 * Google2.java
 * Open Google webpage and search for "Selenium 2".
 * @Author: Xuan Ngo
 */
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class Google2
{
  public static void main(String[] args)
  {
    final String sUrl = "http://www.google.ca/index.html";
    
    // Instantiate the Internet Explorer browser.
    WebDriver oWebDriver = new InternetExplorerDriver();
    
    // Open the main google webpage.
    oWebDriver.get(sUrl);
    
    // Get the search input html element.
    WebElement oSearchInputElem = oWebDriver.findElement(By.name("q")); // Use name locator to identify the search input field.
    
    // Type "Selenium 2" into the search input field.
    oSearchInputElem.sendKeys("Selenium 2");
    
    // Get the Google Search button.
    WebElement oGoogleSearchBtn = oWebDriver.findElement(By.xpath("//input[@name='btnG']"));
    
    // Click on "Google Search" button
    oGoogleSearchBtn.click();

    // Pause for a few seconds so that you can see the result before closing the browser.
    try
    {
      Thread.sleep(5000);
    }
    catch(InterruptedException ex)
    {
      System.out.println(ex.getMessage());
    }
    
    // Close the browser.
    oWebDriver.close();
  }
}
