Selenium Java to compare the title of a given webpage
Codeaft.java
importorg.openqa.selenium.WebDriver;importorg.openqa.selenium.chrome.ChromeDriver;classCodeaft{publicstaticvoidmain(String[]args){System.setProperty("webdriver.chrome.driver","/home/codeaft/drivers/chromedriver");WebDriverdriver=newChromeDriver();driver.navigate().to("https://codeaft.github.io/testapp/");StringactualTitle=driver.getTitle();StringexpectedTitle="Codeaft'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 - Codeaft's TestApp
Expected Title - Codeaft's Testapp
Title Not Matched
Dear User, Thank you for visitng Codeaft. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.