fork download
  1. package net.qaautomation.examples;
  2.  
  3. import org.openqa.selenium.By;
  4. import org.openqa.selenium.WebDriver;
  5. import org.openqa.selenium.firefox.FirefoxDriver;
  6. import org.openqa.selenium.support.ui.ExpectedCondition;
  7. import org.openqa.selenium.support.ui.Wait;
  8. import org.openqa.selenium.support.ui.WebDriverWait;
  9.  
  10. /**
  11.  * Search Google example.
  12.  *
  13.  * @author Rahul
  14.  */
  15. public class GoogleSearch {
  16. static WebDriver driver;
  17. static Wait<WebDriver> wait;
  18.  
  19. public static void main(String[] args) {
  20. driver = new FirefoxDriver();
  21. wait = new WebDriverWait(driver, 30);
  22. driver.get("http://www.google.com/");
  23.  
  24. boolean result;
  25. try {
  26. result = firstPageContainsQAANet();
  27. } catch(Exception e) {
  28. e.printStackTrace();
  29. result = false;
  30. } finally {
  31. driver.close();
  32. }
  33.  
  34. System.out.println("Test " + (result? "passed." : "failed."));
  35. if (!result) {
  36. System.exit(1);
  37. }
  38. }
  39.  
  40. private static boolean firstPageContainsQAANet() {
  41. //type search query
  42. driver.findElement(By.name("q")).sendKeys("qa automation\n");
  43.  
  44. // click search
  45. driver.findElement(By.name("btnG")).click();
  46.  
  47. // Wait for search to complete
  48. wait.until(new ExpectedCondition<Boolean>() {
  49. public Boolean apply(WebDriver webDriver) {
  50. System.out.println("Searching ...");
  51. return webDriver.findElement(By.id("resultStats")) != null;
  52. }
  53. });
  54.  
  55. // Look for QAAutomation.net in the results
  56. return driver.findElement(By.tagName("body")).getText().contains("qaautomation.net");
  57. }
  58. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:15: error: class GoogleSearch is public, should be declared in a file named GoogleSearch.java
public class GoogleSearch {
       ^
Main.java:3: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
                          ^
Main.java:4: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;
                          ^
Main.java:5: error: package org.openqa.selenium.firefox does not exist
import org.openqa.selenium.firefox.FirefoxDriver;
                                  ^
Main.java:6: error: package org.openqa.selenium.support.ui does not exist
import org.openqa.selenium.support.ui.ExpectedCondition;
                                     ^
Main.java:7: error: package org.openqa.selenium.support.ui does not exist
import org.openqa.selenium.support.ui.Wait;
                                     ^
Main.java:8: error: package org.openqa.selenium.support.ui does not exist
import org.openqa.selenium.support.ui.WebDriverWait;
                                     ^
Main.java:16: error: cannot find symbol
    static WebDriver driver;
           ^
  symbol:   class WebDriver
  location: class GoogleSearch
Main.java:17: error: cannot find symbol
    static Wait<WebDriver> wait;
           ^
  symbol:   class Wait
  location: class GoogleSearch
Main.java:17: error: cannot find symbol
    static Wait<WebDriver> wait;
                ^
  symbol:   class WebDriver
  location: class GoogleSearch
Main.java:20: error: cannot find symbol
        driver = new FirefoxDriver();
                     ^
  symbol:   class FirefoxDriver
  location: class GoogleSearch
Main.java:21: error: cannot find symbol
        wait = new WebDriverWait(driver, 30);
                   ^
  symbol:   class WebDriverWait
  location: class GoogleSearch
Main.java:42: error: cannot find symbol
        driver.findElement(By.name("q")).sendKeys("qa automation\n");
                           ^
  symbol:   variable By
  location: class GoogleSearch
Main.java:45: error: cannot find symbol
        driver.findElement(By.name("btnG")).click();
                           ^
  symbol:   variable By
  location: class GoogleSearch
Main.java:48: error: cannot find symbol
        wait.until(new ExpectedCondition<Boolean>() {
                       ^
  symbol:   class ExpectedCondition
  location: class GoogleSearch
Main.java:56: error: cannot find symbol
        return driver.findElement(By.tagName("body")).getText().contains("qaautomation.net");
                                  ^
  symbol:   variable By
  location: class GoogleSearch
16 errors
stdout
Standard output is empty