Selenium Java to compare the title of a given webpage
KW.java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

class KW 
{
    public static void main(String[] args) 
    {
        System.setProperty("webdriver.chrome.driver", "/home/kodingwindow/drivers/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.navigate().to("https://kodingwindow.com/testapp/");

        String actualTitle = driver.getTitle();
        String expectedTitle = "Kodingwindow's Testapp";

        System.out.println("Actual Title - "+actualTitle);
        System.out.println("Expected Title - "+expectedTitle);
        
        if(actualTitle.contentEquals(expectedTitle))
        {
            System.out.println("Title Matched");
        }
        else
        {
            System.out.println("Title Not Matched");
        }
        driver.close();
    }
}
Output
Actual Title - Kodingwindow's TestApp
Expected Title - Kodingwindow's Testapp
Title Not Matched
What Next?
Selenium Locators
Advertisement