title: How to get caption/text of button in WebDriver using Java
body: <p>I have the following HTML code for "Save" button:</p>
  
  <pre><code>&lt;input type="submit" onclick="return confirm('Sure to change global settings?')" value="Save" name="submit"&gt;
  </code></pre>
  
  <p>I want to retrieve the caption of button. I used the following code to do that:</p>
  
  <pre><code>String actualButtonCaption = driver.findElement(By.xpath("//input[@value='Save']")).getText();
  </code></pre>
  
  <p>I also used the absolute xpath as below:</p>
  
  <pre><code>String actualButtonCaption = driver.findElement(By.xpath("//html/body/form/div[3]/div[2]/input")).getText();
  </code></pre>
  
  <p>But unfortunately, no text was retrieved. Blank/empty text was found. Can anybody help me?</p>