Apparently, your code was pretty good enough to retrieve the title as Google
. However, this discussion points us to a couple of simple facts about String
literals in Java
as follows:
==
tests should be used for reference equality (if they are the same object).
.equals()
tests should be used for value equality (if they are literally equal).
Hence changing if (c!="Google")
to if (!c.equals("Google"))
should have solved your purpose.
Getting Granular:
As we are comparing string literals, my take will be to get more granular and use if (!c.contentEquals("Google"))
instead of if (!c.equals("Google"))
.
Solution:
Hence a proper solution to your problem will be to define the if()
as follows:
public class GooglePageTitle
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver=new FirefoxDriver();
driver.get("https://www.google.com");
String c;
c = driver.getTitle();
if (!c.contentEquals("Google"))
System.out.println("True");
driver.close();
}
}