12

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...

jabbett
  • 524
  • 1
  • 7
  • 20
  • 2
    I've submitted this [as a bug](http://code.google.com/p/selenium/issues/detail?id=5165&q=anchor&colspec=ID%20Stars%20Type%20Status%20Priority%20Milestone%20Owner%20Summary) to the Selenium team. – jabbett Mar 19 '13 at 14:46
  • I'm observing the same behavior, but despite the timeout error, my script will then continue – Dexygen May 13 '13 at 15:48
  • As a note to any one else who is experiencing my similar yet different case, I could not load a url in selenium such as `https://foo.com#bar`. However, Selenium **will** accept url hashes if the hash is followed by a forward-slash, i.e. `https://foo.com#/bar`. – Walter Roman Mar 31 '15 at 05:14

3 Answers3

5

In Selenium IDE simply use the 'storeEval' command, for example :

Command = storeEval
Target = window.location.hash='/search/events/birthdays/1' 

storeEval runs the javascript snippet assigned to "target". What you can then do, is have one test case that opens the start page using the open(url) command, and the rest of your cases changing the hash using the storeEval command.

Sasha Brocato
  • 573
  • 9
  • 14
1

Run this on console of developer tool -> window.location.hash='#abcde'. It should change hash for you in the browser tab.

Execute javascript through Selenium Webdriver and Java:

((JavascriptExecutor) driver).executeScript("window.location.hash='#abcde'");
daddycool
  • 107
  • 1
  • 1
  • 7
0

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())
jabbett
  • 524
  • 1
  • 7
  • 20