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 & tell you what I want to do with this code.
it will open https://www.facebook.com
, on Facebook homepage, class name of "First Name" field is "inputtext _58mg _5dba _2ph-". So I created a string variable cname1
that will store class value of current focused element in loop, and cname2
variable has value "inputtext _58mg _5dba _2ph-" , then I compare these 2 in do while loop, and loop should stop when cname1
& cname2
are equal.
But it is not working, it stops in password field of Facebook instead of running until First Name field. Thanks
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) {}
}