Unable to Assert Login-getTitle() still giving "Log In" page title after logging in when it is "Home

264 views
Skip to first unread message

Sarika Raheja

unread,
May 13, 2016, 3:41:40 AM5/13/16
to Selenium Users
Pls help:

I want to assert if login is successful after logging in. After logging in i want to verify if the page title is "Home". But code still giving page title as "Log In"
I am using Sel WebDriver 2.53 and IE -11

code:

package pack1;

import java.util.concurrent.TimeUnit;

import org.junit.Assert;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


public class Login {

public static void main(String[] args) {
System.setProperty("webdriver.ie.driver", "E:\\Testing\\Training Selenium\\qspiders\\IEDriverServer.exe");
WebDriver driver=new InternetExplorerDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.cssSelector("input[id='UserName']")).sendKeys("sdfsdfdsf");
WebElement pwd=driver.findElement(By.cssSelector("input[id='Password']"));
pwd.sendKeys(Keys.CONTROL,"a");
pwd.sendKeys("Password@123");
driver.findElement(By.cssSelector("input[value='Sign In']")).click();
WebDriverWait wait=new WebDriverWait(driver,60);
wait.until(ExpectedConditions.titleContains("Home"));
System.out.println(driver.getTitle());
Assert.assertEquals(driver.getTitle(),"Home");
driver.close();
}

}

Punkaaj Chavaan

unread,
May 16, 2016, 6:31:53 AM5/16/16
to Selenium Users
Are you able to successfully login using given code?
First you should check if you are successfully logged in, comment the driver.close() line and re-run the code.
My guess is that you are not getting logged in successfully and that's why title is not getting changed to "Home".

Regards,
Punkaaj

Sarika Raheja

unread,
May 16, 2016, 6:35:08 AM5/16/16
to Selenium Users
Hi Punkaaj

Thanks for your kind reply. 
I am successfully able to login...But the result is still the title page of the Log In page and not the home page inspite of the wait i have provided

Punkaaj Chavaan

unread,
May 16, 2016, 7:18:54 AM5/16/16
to Selenium Users
If you could provide stack trace and console output and if possible, complete info (like URL, login, pwd) will be needed to re-create the problem at my end.

Regards,
Punkaaj

Sarika Raheja

unread,
May 16, 2016, 7:47:02 AM5/16/16
to Selenium Users

Hi Punkujj

I am still a beginner in Selenium,,, so still learning to build a framework and write complex scripts and all,,,
for the time being its just a simple login script that i have written. Attaching the java file. and the Console Error.

(URL and credentials in the file)

I am using selenium webdriver version 2.53
Actitime.java
Console Error.txt

Punkaaj Chavaan

unread,
May 16, 2016, 9:37:51 AM5/16/16
to Selenium Users
Just replace this line in your code = wait.until(ExpectedConditions.titleContains("actiTIME -  Enter Time-Track"));
to this line =        wait.until(ExpectedConditions.titleIs("actiTIME - Enter Time-Track"));

Webdriver is not able to correctly match title as you are using "titleContains" method instead use "titleIs" method.

The other way is to remove the explicit wait statements from the code and replace it with Thread.sleep(10000), but it is not recommended way.

Regards,
Punkaaj

Sarika Raheja

unread,
May 16, 2016, 1:16:46 PM5/16/16
to seleniu...@googlegroups.com
Hi Punkaaj

I am really grateful for your time to reply. Did you execute the script that i sent?
I replaced the one line with the one that you sent. But i am still getting the same error.
Is there anything else that i can try?

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/4e91a5ed-8129-448a-9c20-88129c1979e4%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

punkaaj chavaan

unread,
May 18, 2016, 5:43:21 AM5/18/16
to seleniu...@googlegroups.com
Hi Sarika,

Here's the script that is working at my end, run the same at your end and let me know if there's any problem. For explanation on DesiredCapabilities that I have set, check out my blog - http://selenium-coding.blogspot.in/2016/04/running-selenium-tests-on-internet.html

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;

public class ActiTimeTC {


    public static void main(String[] args) {
        WebDriver driver = null;

        System.setProperty("webdriver.ie.driver",
                "D:\\bckup\\Documents\\Documents\\Selenium\\InternetExplorerDriver\\IEDriverServer_Win32_2.53.0\\IEDriverServer.exe");
        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
        capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        capabilities.setCapability("requireWindowFocus", true);
        capabilities.setCapability("ignoreProtectedModeSettings", false);
        driver = new InternetExplorerDriver(capabilities);
       
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
        driver.get("http://demo.actitime.com");

        driver.findElement(By.cssSelector("input[id='username']")).sendKeys("admin");
        driver.findElement(By.xpath(".//*[@name='pwd']")).sendKeys("manager");
        driver.findElement(By.xpath(".//*[@id='loginButton']/div")).click();
        WebDriverWait wait = new WebDriverWait(driver, 60);


        wait.until(ExpectedConditions.titleIs("actiTIME - Enter Time-Track"));
        Assert.assertEquals(driver.getTitle(), "actiTIME - Enter Time-Track");
        System.out.println(driver.getTitle());
        driver.close();


    }

}

Regards,
Punkaaj


--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/nEF2q7g5PPY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages