2

So, I have this code, where I am trying to compare the text that I saved in Y variable with the text from x variable. The problem is that eclipse doesn't save in the variable x the text from that locator. If I try to print the variable x I got printed "SECTOR 3, BUCURESTI", which is the same text saved in y. But when I compare them I always get the error message.

String y = "SECTOR 3, BUCURESTI";
        
        WebElement LA = driver.findElement(By.xpath("//a[@href='#']//div//div//div[contains(text(),'SECTOR 3, BUCURESTI')]"));
        String x= LA.getText();
        if (x == y) {
            System.out.println(x);
        } else {
            System.out.println("error");
        }

1 Answers1

2

Please refer to this link to understand more about String comparision

Reference link

Basically,

you should use String.equals() rather than '==' operator, I think that's what is throwing the error.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
Long Doan
  • 91
  • 8