getPageSource from all pages on load in selenium

I’m trying to checking with selenium if my automated login was successfully or not. Since there are my app supports multiple login types I’m relying on commonly used id element (logout and signOut) and keywords (logout/signout) to identify if the login was successful.

In most cases the logic works but in some cases the app has two different pages on load index.html which has the logout button and the actual page source code(example say dashboard.html).

When i use selenium driver to getPageSource i get the source code for dashboard and as such my test case fails as the source code doesn’t contain logout keyword.

Whats the best way to get html source code for all pages when a urls loads ?

Generally analyzing page’s source code to define current application state is wrong approach: there may be JS, Ajax scripts, CSS / other code that can modify app behaviour & browser page’s rendering.

That’s why WebDriver team aims to test actual page UI which the user sees. So, WebDriver tests should test elements that present in browser and rely on different elements’ locating techiques.

I recommend using element id’s, xpath to locate LogOut / LogIn buttons with usage of explicit waits in your case. Do not work with page source – work with elements on page.