title: selenium: how to click a page link
body: <p>Am using cucumber with selenium-webdriver however, clicking a link on the page doesn't working.</p>
  
  <p>the HTML code:</p>
  
  <pre><code>  &lt;li id="menu-item-325" class="menu-item menu-item-type-post_type menu-item-object-page  menu-item-325"&gt;
    &lt;a href="mysite/contact/" class="nav-top-link"&gt;Contact&lt;/a&gt;
   &lt;/li&gt;
  </code></pre>
  
  <p>Test code:</p>
  
  <pre><code>const { defineSupportCode } = require('cucumber');
  const { Builder, By } = require('selenium-webdriver');
  
  const driver = new Builder()
      .forBrowser('chrome')
      .build();
  
  defineSupportCode(function ({ Given, When, Then }) {
    // Navigation to the url works
    Given('I am on the site homepage', function () {
      return driver.get(url);
    });
  
    When('When I click Contact', function() {
      return driver.findElement(By.linkText('Contact')).click();
    });
  });
  </code></pre>
  
  <p>I also tried:</p>
  
  <p><code>return driver.findElement(By.xpath("//a[@href='mysite/contact/']")).click();</code></p>