title: WebDriver with Java - click to open a link using xpath
body: <p>I want to open a a link on a webpage. The link appears to be within a unordered list which resides within in a  tag. The url to the web page is selftechy dot com. The tabs are home, about, selenium. </p>
  
  <p>I attempted to open the link using <code>driver.findElement(By.linkText("Selenium"));</code> but page seems like lost its styling. I also tried with xpath method, but it doesn't work either. Please explain to me why it doesn't work and how should I modify the code to make it work properly. Thanks for your help.</p>
  
  <p>HTML code fragment: </p>
  
  <pre><code>&lt;body class="custom"&gt;
  &lt;div id="container"&gt;
  &lt;div id="page"&gt;
  &lt;ul class="menu"&gt;
  &lt;li class="tab tab-home current"&gt;&lt;a href="http://selftechy.com"&gt;Home&lt;/a&gt;&lt;/li&gt;
  &lt;li class="tab tab-1"&gt;&lt;a href="http://selftechy.com/about" title="About"&gt;About&lt;/a&gt;&lt;/li&gt;
  &lt;li class="tab tab-2"&gt;&lt;a href="http://selftechy.com/selenium-2" title="Selenium"&gt;Selenium&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>webdriver code to open the link</p>
  
  <pre><code>import java.util.List;
  import java.util.concurrent.TimeUnit;
  import org.junit.*;
  
  import org.junit.Before;
  import org.junit.After;
  import org.openqa.selenium.*;
  import org.openqa.selenium.firefox.FirefoxDriver;
  import org.openqa.selenium.support.ui.Select;
  
  public class selftechyTestng 
  {
      private WebDriver driver;
      private String baseUrl;
  
      @Before
      public void setUp() throws Exception
      {
          driver = new FirefoxDriver();
          baseUrl = "http://selftechy.com/";
          driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      }
      @Test
      public void searchElements() throws Exception{
          driver.get(baseUrl);
  
              //use By.linkText method the page lost its styling
              driver.findElement(By.linkText("Selenium"));
  
          //use xpath method to open the link doesn't work either 
          List&lt;WebElement&gt; elements = driver.findElements(By.xpath("//div[@id=page]/*[3]")).click(); 
          driver.findElement(By.xpath("//div[@id=page]/*[3]")).click(); 
      }
  
  }
  </code></pre>