title: Selenium Java variables access
body: <p>I need to know a way to access variables of a method from a class in other methods or other class.</p>
  
  <p>example below: i have put all locators of a registration page in one method elements() and then i am trying to use the identifiers e1 in the main method of the same class A and in other class B i have created a object reference of Class A and then trying the same. its not working and i need to know the correct way here.</p>
  
  <pre><code>public class test3 {
  
       public void elements(){
  
       By e1=By.id("at-i");
       By e2=By.xpath("//td/td[2]");
  
      }
  
       public static void main (String args[])
       {
  
       WebDriver driver=new FirefoxDriver();
       driver.get("http://testwebsite.com");
       WebElement a1=driver.findelement(e1);
  
       }
      }
  
      class b{
  
       public static void main (String args[]) {
  
           test3 x=new test3();
  
           Webelement a2=x.driver.findelement(e2);
  
       }   
  }
  </code></pre>