Search code examples
javascriptbackbone.jsseleniumhashchange

How to open a URL with a hash using Selenium?


I'm trying to test my Backbone.js web application with Selenium IDE.

Selenium can open my test case's initial URL so long as it's in a fresh browser window -- e.g. open /#/login -- but it times out whenever it tries to open subsequent URLs.

It seems that Selenium is listening for an event that just isn't triggered when only the URL hash changes.

I would imagine this happens any time you're using hashchange + Selenium...


Solution

  • A brief update: We gave up trying to use Selenium IDE to write our integration tests, and instead used the Selenium Python bindings for Selenium WebDriver.

    With this approach, we can navigate to a URL and then use WebDriverWait to detect a particular change in the DOM, e.g.

    driver = webdriver.Firefox()
    driver.get("/#/login")
    WebDriverWait(driver, 10).until(
        lambda driver: driver.find_element_by_css_selector("form.login").is_displayed())