title: Compare Strings in Do While Loop Java
body: <p>I am learning Selenium in Java. I want to compare 2 strings in do while loop, I want loop to keep running unless my 2 strings value has been equal, when value is equal then loop should stop. 
  Now I show you my code &amp; tell you what I want to do with this code. 
  it will open <code>https://www.facebook.com</code> , on Facebook homepage, class name of "First Name" field is "inputtext _58mg _5dba _2ph-". So I created a string variable <code>cname1</code> that will store class value of current focused element in loop, and <code>cname2</code> variable has value "inputtext _58mg _5dba _2ph-" , then I compare these 2 in do while loop, and loop should stop when <code>cname1</code> &amp; <code>cname2</code> are equal. 
  But it is not working, it stops in password field of Facebook instead of running until First Name field. Thanks</p>
  
  <pre><code>public class HelloWorldTest {
  private static String cname1;
  private static String cname2;
  
  public static void main(String[] args) {
  
  WebDriver driver = new FirefoxDriver();
  driver.get("https://www.facebook.com/"); 
  driver.findElement(By.id("email")).click(); 
  
  do {
       driver.switchTo().activeElement().sendKeys(Keys.TAB);
       WebElement element = driver.switchTo().activeElement();
       String cname1 = element.getAttribute("class");
       String cname2 = "inputtext _58mg _5dba _2ph-";
       System.out.println(cname1);
       System.out.println(cname2);
      }
      while ( cname1 != cname2 );
  }
  
  private void sendKeys(Keys enter) {}
  
  }
  </code></pre>