I'm looking for methods to assert that an action caused the expected navigation. For example, after logging out, I want to assert that I'm back at the login page.

At first I did an assert on the (relative) URL, but it didn't feel right. As a second attempt, I try to access an element that should be on the page.

var loginPage = new LoginPage(this.Driver)

var assert = loginPage.LoginButton.ToString();

If it doesn't throw, then it can be said with reasonable certainty that the test is successful.

Are there any other methods that you've had success with?

  • are you using a framewor such as JUnit or TestNG In your project or are you relying on Java asserts?
    – ECiurleo
    Jan 12, 2016 at 10:49
  • 2
    @ECiurleo I'm using xUnit.net, it's a C# project.
    – Stijn
    Jan 12, 2016 at 10:53

2 Answers 2


I would assert an expected element is present on the returned page using NUnit eg

        Assert.AreEqual(loginPage.LoginButton.ToString(), "Login");

Common elements to use would be;

  • an ID (unique element on the page)
  • Page Title
  • Contextual (like the example above).

Avoid using things like the URL which often contain things like session information (and therefore subject to change)


You can try to assert a text in the page you are navigating to.

You can also assert page/window title.

Another way to assert whether an image or an element specific to that page is present or not.

  • The window title sounds good. More stable than an URL, and easier than choosing an element for each page.
    – Stijn
    Jan 12, 2016 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.