title: Xpath for button having text as 'New'
body: <p>In our application almost in every screen we have a button with text 'New', Here is the html source for one of the button:</p>
  
  <pre><code>&lt;button id="defaultOverviewTable:j_id54" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-state-hover" type="submit" name="defaultOverviewTable:j_id54" role="button" aria-disabled="false"&gt;
      &lt;span class="ui-button-text ui-c"&gt;New&lt;/span&gt;
  &lt;/button&gt;
  </code></pre>
  
  <p>I have tried using the below statement to click on the button:</p>
  
  <pre><code>driver.findElement(By.xpath("//button[[@type, 'submit'] and [text()='New']]")).click();
  </code></pre>
  
  <p>But this was not working  </p>
  
  <pre><code>org.openqa.selenium.InvalidSelectorException: The given selector //button[[@type= 'submit'] and [text()='New']] is either invalid or does not result in a WebElement.
  </code></pre>
  
  <p>Currently I am using the below code to click on the button:</p>
  
  <pre><code>List&lt;WebElement&gt; allButt = driver.findElements(By.tagName("button"));
  for (WebElement w : allButt)
  {
      if (w.getText().matches("New"))
      {
          w.click();
          break;
      }
  }
  </code></pre>
  
  <p>As I have almost 150 buttons in the page. Is there any other way?</p>