title: Finding Hidden/Disabled Element using Xpath
body: <p>I'm trying to find button(Preview/Edit) on a webpage by using this code where it will click the button according to the argument text(buttonName).</p>
  
  <p>The page behaves {when the page loads, it shows you 'edit' button. If you click edit then it shows 'preview' button and vice versa}</p>
  
  <pre><code>WebBrowserElement parentElement = waitForElement(By.xpath("//div[@class='serviceHeaderInner']"));
  String s = parentElement.toString();
  if (s.contains(buttonName) &amp;&amp; (parentElement.waitForElement(By.xpath(".//a[.='" + buttonName + "']"))).isDisplayed()) {
      WebBrowserElement buttonElement = parentElement.waitForElement(By.xpath(".//a[.='" + buttonName + "']"));
      buttonElement.click();
  } else {
      debugPrintln("        -&gt; Invalid  buttonName '"+ buttonName +"'");
  }
  </code></pre>
  
  <p>In the test case I'm trying to pass,</p>
  
  <p>'Preview'</p>
  
  <p>'Preview'</p>
  
  <p>'Edit'</p>
  
  <p>'Edit'</p>
  
  <p>As when the page loads, there will be 'Edit' button and passing 'Preview' arguments twice in test case.. it goes directly to else and so on.Moreover passing 'Edit' argument also goes to the else portion. I guess there's something wrong with the "if" condition. But to make more dynamic "It should check for class which contains 'disabled' text acc. to the snapshots, so that this problem could be prevented at the first point.</p>
  
  <p>Snapshots:
  <a href="http://i.stack.imgur.com/AvtgZ.png" rel="nofollow">1</a> and <a href="http://i.stack.imgur.com/44rqf.jpg" rel="nofollow">2</a></p>