Browser test fixes

Depends on #471 (but can be reviewed independently, as the changes here are confined to browser_tests.py, and most #471 changes are not in that file).

This was done independently of @bcipolli's fixes to the tests, and ended up being almost exactly the same solutions, so I took what I considered to be the best of both and combined them here.