obernardovieira

Open google search with Selenium [Chrome]

Mar 3rd, 2017
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. package com.obernardovieira.seleniumChrome;
  2.  
  3. import java.util.logging.Logger;
  4.  
  5. import org.junit.Test;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebDriver;
  8. import org.openqa.selenium.WebElement;
  9. import org.openqa.selenium.chrome.ChromeDriver;
  10.  
  11. /**
  12.  * Hello world!
  13.  *
  14.  */
  15. public class App
  16. {
  17.     private static Logger LOG = Logger.getLogger(App.class.getSimpleName());
  18.     public static void main( String[] args )
  19.     {
  20.         LOG.log( null, "Hello World!" );
  21.     }
  22.    
  23.     @Test
  24.     public void testGoogleSearch() {
  25.         // Optional, if not specified, WebDriver will search your path for chromedriver.
  26.         System.setProperty("webdriver.chrome.driver", "chromedriver");
  27.        
  28.         WebDriver driver = new ChromeDriver();
  29.         driver.get("http://www.google.com/xhtml");
  30.  
  31.         try {
  32.             Thread.sleep(5000);
  33.         } catch (InterruptedException e) {
  34.             LOG.log( null, e.getMessage() );
  35.             Runtime.getRuntime().exit(1);
  36.         }
  37.         // Let the user actually see something!
  38.         WebElement searchBox = driver.findElement(By.name("q"));
  39.         searchBox.sendKeys("ChromeDriver");
  40.         searchBox.submit();
  41.         try {
  42.             Thread.sleep(5000);
  43.         } catch (InterruptedException e) {
  44.             LOG.log( null, e.getMessage() );
  45.             Runtime.getRuntime().exit(1);
  46.         }
  47.         // Let the user actually see something!
  48.         driver.quit();
  49.     }
  50. }
Add Comment
Please, Sign In to add comment