getTitle() method does not work in Selenium



  • In some instances, the getTitle() method does not work for me. Take a look. @Test public void testTitleReliability() { driver.get("https://www.google.com"); boolean title = driver.getTitle() == "Google"; if(title) System.out.println("I am working correctly"); else if(!title) System.out.println("I am broken!"); However, it will work with this: @Test public void testTitleReliability() { driver.get("https://www.google.com"); boolean title = driver.getTitle().contains("Google"); if(title) System.out.println("I am working correctly"); else if(!title) System.out.println("I am broken!"); Anyone know why?



  • The "==" operator checks objects for identity, not for equality. Try this instead: driver.getTitle().equals("Google")



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2