title: Click a button using selenium and xpath
body: <p>I'm trying to click a button called Add new alert:</p>
  
  <pre><code>&lt;div class="text-right"&gt;
  &lt;a class="btn btn-primary " data-ajaxcom="" href="/admin/person/59139/alerts/add"&gt;
  &lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt;
  Add new alert
  &lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Below is my code:  </p>
  
  <pre><code>    &lt;?php
  
      // Load up the composer autoloader, which will allow us to use the composer
      // stuff
      require 'vendor/autoload.php';
  
      $driver = new \Behat\Mink\Driver\Selenium2Driver(
          'firefox', 'base_url'
      );
  
      // init session:
      $session = new \Behat\Mink\Session($driver);
  
      // start session:
      $session-&gt;start();
  
      $session-&gt;visit('http://www.mywebsite.com/admin');
  
      $session-&gt;wait(400 + rand(0, 100));
      $page = $session-&gt;getPage();
      $page-&gt;fillField('username', 'admin');
      $page-&gt;fillField('password', 'password');
      $page-&gt;pressButton('submit');
  
      $session-&gt;visit('http://www.mywebsite.com/admin/person/59139');
      function clickbtnwithxpath($xpath)
          {
              $session = $this-&gt;getSession();
              $element = $session-&gt;getPage()-&gt;find(
                  '//a[contains(@class, "btn btn-primary ")]',
                  $session-&gt;getSelectorsHandler()-&gt;selectorToXpath('//a[contains(@class, "btn btn-primary ")]', $xpath)
              );
  
              // error handling
              if (null === $element) {
                  throw new \InvalidArgumentException(sprintf('Could not evaluate XPath: "%s"', $xpath));
              }
  
              // click button
              $element-&gt;click();
  
          }
  ?&gt;
  </code></pre>
  
  <p>It logs me in and goes to the alert page but it will not click the button. I am a complete newbie with xpath. I think it's here where there must be an error. But I've made an attempt. Could someone please help me get this working?</p>