Reputation: 79
I Need to verify title of a webpage after login is done. Using the Chrome Driver for selenium the title of page after login is coming correct but not firefox driver. Rest of the code remains same, just the driver was changed from chrome to firefox.
public void verifyLoginPage()
{
String homepage= "Guru99 Bank Manager HomePage";
if (driver.getTitle().equals(homepage))
{
System.out.println("Its the correct Homepage after Login");
}
else
{
System.out.println("Page after login is not the intended one");
}
}
With Chrome driver this code returns " Its the correct Homepage after Login" and with firefox driver this code returns " Page after login is not the intended one" , as getTitle returns the title of login page, not after login.
Upvotes: 1
Views: 4835
Reputation: 193088
Different browser renders the HTML DOM in a different way. You can find a relevant discussion in Chrome & Firefox on Windows vs Linux (selenium). At this point it is worth to be mentioned that:
It seems in your usecase:
While using ChromeDriver / Chrome, the Page Title is already rendered within the DOM Tree by the time document.readyState
equals to complete
is attained.
But while using GeckoDriver / Firefox, the Page Title is not rendered within the DOM Tree by the time document.readyState
equals to complete
is attained.
You need to induce WebDriverWait for the title to contain and you can use the following solution:
public void verifyLoginPage()
{
new WebDriverWait(driver, 20).until(ExpectedConditions.titleContains("Guru99");
String homepage= "Guru99 Bank Manager HomePage";
if (driver.getTitle().equalsIgnoreCase(homepage))
System.out.println("Its the correct Homepage after Login");
else
System.out.println("Page after login is not the intended one");
}
Upvotes: 1
Reputation: 1996
Can you please try to execute below code and let's know if it worked.
Once you have opened chrome or Firefox driver, after that please add below code and see -
driver.manage().timeouts().implicitlyWait(10
driver.navigate().to("http://sitename.com");
String actualTitle = driver.getTitle();
driver.manage().window().maximize();
String expectedTitle = "page title to be verified";
if(actualTitle.equalsIgnoreCase(expectedTitle))
System.out.println("Title Matched");
else
System.out.println("Title didn't match");
driver.close();
driver.quit();
Upvotes: 1