Fix and refactor Selenium tests