title: Selenium WebDriver first Java example to set up
body: <p>I created pom.xml and an example file Selenium2Example.java to set up Maven.
  I followed the instructions on here <a href="http://seleniumhq.org/docs/03_webdriver.html#chrome-driver" rel="nofollow">http://seleniumhq.org/docs/03_webdriver.html#chrome-driver</a></p>
  
  <p>But I am getting the error <strong>"Selection does not contain a main type"</strong> on running Selenium2Example.java as Java Application.</p>
  
  <p>Here is the pom.xml I am using</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" &gt;
          &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
          &lt;groupId&gt;MySel20Proj&lt;/groupId&gt;
          &lt;artifactId&gt;MySel20Proj&lt;/artifactId&gt;
          &lt;version&gt;1.0&lt;/version&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
                  &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
                  &lt;version&gt;2.25.0&lt;/version&gt;
              &lt;/dependency&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;com.opera&lt;/groupId&gt;
                  &lt;artifactId&gt;operadriver&lt;/artifactId&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
          &lt;dependencyManagement&gt;
              &lt;dependencies&gt;
                  &lt;dependency&gt;
                      &lt;groupId&gt;com.opera&lt;/groupId&gt;
                      &lt;artifactId&gt;operadriver&lt;/artifactId&gt;
                      &lt;version&gt;0.16&lt;/version&gt;
                      &lt;exclusions&gt;
                          &lt;exclusion&gt;
                              &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
                              &lt;artifactId&gt;selenium-remote-driver&lt;/artifactId&gt;
                          &lt;/exclusion&gt;
                      &lt;/exclusions&gt;
                  &lt;/dependency&gt;
              &lt;/dependencies&gt;
          &lt;/dependencyManagement&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Here is the Selenium2Example.java I am using:</p>
  
  <pre><code>package org.openqa.selenium.example;
  
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.Chrome.ChromeDriver;
  import org.openqa.selenium.support.ui.ExpectedCondition;
  import org.openqa.selenium.support.ui.WebDriverWait;
  
  public class Selenium2Example  {
      public static void main(String[] args) {
          // Create a new instance of the Chrome driver
          // Notice that the remainder of the code relies on the interface, 
          // not the implementation.
          WebDriver driver = new ChromeDriver();
          // And now use this to visit Google
          driver.get("http://www.google.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
          WebElement element = driver.findElement(By.name("q"));
  
          // Enter something to search for
          element.sendKeys("Cheese!");
          // Now submit the form. WebDriver will find the form for us from the element
          element.submit();
  
          // Check the title of the page
          System.out.println("Page title is: " + driver.getTitle());
  
          // Google's search is rendered dynamically with JavaScript.
          // Wait for the page to load, timeout after 10 seconds
          (new WebDriverWait(driver, 10)).until(new ExpectedCondition&lt;Boolean&gt;() {
              public Boolean apply(WebDriver d) {
                  return d.getTitle().toLowerCase().startsWith("cheese!");
              }
          });
          // Should see: "cheese! - Google Search"
          System.out.println("Page title is: " + driver.getTitle());        
          //Close the browser
          driver.quit();
      }
  }
  </code></pre>
  
  <p>On running it gives the following error 
  Run as -> Run config -> (selecting Selenium2Example.java under TestNG</p>
  
  <p>The error is </p>
  
  <pre><code>org.testng.TestNGException: 
  Cannot find class in classpath: Selenium2Example
      at org.testng.xml.XmlClass.loadClass(XmlClass.java:76)
      at org.testng.xml.XmlClass.init(XmlClass.java:68)
      at org.testng.xml.XmlClass.&lt;init&gt;(XmlClass.java:54)
      at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:542)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
      at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
      at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:766)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1302)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2715)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
      at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:488)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
      at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
      at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
      at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
      at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
      at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302)
      at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
      at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
      at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
      at org.testng.xml.Parser.parse(Parser.java:172)
      at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:310)
      at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
  </code></pre>