title: How can i get the xpath from a WebElement
body: <p>How can i get the xpath from a WebElement</p>
  
  <pre><code>Webelement element= driver.findElement(By.xpath("//div//input[@name='q']"));
  </code></pre>
  
  <p>something like</p>
  
  <pre><code>element.getLocator(); -&gt;&gt; this should be like this "//div//input[@name='q']"
  </code></pre>
  
  <p>how to do the same?
  I have created below method and passed xpath as parameter. I want to create same method and pass webElement as parameter:</p>
  
  <pre><code>public boolean isElementPresentAndVisible(String xpath){
      if(driver.findElements(By.xpath(xpath)).size()!=0){
          if(driver.findElement(By.xpath(xpath)).isDisplayed()){
              System.out.println(xpath+" present and Visible");
              return true;
          }else{
              System.err.println(xpath+" present but NOT Visible");
              return false;
          } 
      }else{
          System.err.println(xpath+" NOT present");
          return false;
      } 
  
  }
  </code></pre>