Fix intermittent failures in functional tests

Selenium's implicitly_wait is unreliable in certain contexts (for
example, when checking the current URL or examining the current page
source). Adds an explicit polling wait function that takes an assertion.

Fixes #622
Avoid broken pipe error by waiting for page reload

The "broken pipe" error generally occurs when Flask (which runs in
single-threaded mode in development and testing by default) gets a
request while it is still processing the previous one. This was
happening in the case of testing editing a user's password because:

1. Make a POST request to /admin/edit to change a user's password
2. scrypts the new password, which takes several hundred ms
3. Calls _logout, which uses `self.driver.get` directly and does not
wait for the page to reload.

Therefore, we request the logout page while Flask is still rendering the
"change user password" response to return. This is a race condition, and
so could occur anywhere, but was occurring consistently here due to this
code path using scrypt.

Fixes #623.
Merge pull request #624 from freedomofpress/fix-intermittent-functional-test-error

Fix intermittent functional test errors