String之“==”与equals

时间:2021-09-17 13:14:36

有时候String类型用“==”判断相等时无法成功,经过实验,用string.equals方法可以判断成功!!

for (int i = 0; i < 10000; i++) {
   String readyState = (String) ((JavascriptExecutor) driver)
     .executeScript("var readyState = document.getElementById(\"ContentFrame\").readyState;return readyState");
   if (readyState == "loading"||readyState.equals("loading") || readyState == "complete"||readyState.equals("complete")) {
    System.out.println(readyState);
    System.out.println("点击成功。。。。。。。。。。。。。");
    break;
   } else {
    System.out.println(readyState);
    ((JavascriptExecutor) driver).executeScript(
      "arguments[0].click();", e);
   }