无法将字符串与从属性文件中读取的另一个字符串进行比较

Couldn't compare a string with another one that is read from properties file

我正在自动执行位置选择测试。选项将在下拉菜单中。下拉菜单中有三个选项(位置)。根据所选位置,页面上的数据将相应更改。我正在尝试将位置存储在属性中并从中检索。属性文件中的位置如下所示:

location=UK

检索位置的代码属性:

Properties prop = new Properties();
prop.load(f);
setLocation(prop.getProperty("location"));

当我尝试打印位置 属性 时,显示的是正确的值。

System.out.println(prop.getProperty("location")); //The value  UK is displayed

setLocation()方法代码为:

wait.until(ExpectedConditions.visibilityOf(selectLocation));
selectLocation.click(); //now the dropdown will be displayed
Actions action = new Actions(driver);

if(location == "UK") {
    wait.until(ExpectedConditions.visibilityOf(ukLocation));
    action.moveToElement(ukLocation).click().build().perform();
    }
else if(location == "US") {
        wait.until(ExpectedConditions.visibilityOf(usLocation));
        action.moveToElement(usLocation).click().build().perform();
    }else {
        System.out.println("didn't get the location");
    }

当我运行代码

"didn't get the location"

正在显示。 我已经实现了 URL 的属性并且它起作用了。在这里我可以获得位置 属性 并将其显示在控制台上,但问题出现在字符串比较时。如果我将字符串作为位置传递,则 setLocation() 方法有效:

setLocation("UK"); 

尝试使用 .equals 而不是 ==

 if(location.equals("UK")) {