admin管理员组

文章数量:1287584

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

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

Share Improve this question asked Feb 13, 2013 at 19:53 jabbettjabbett 6211 gold badge8 silver badges21 bronze badges 3
  • 2 I've submitted this as a bug to the Selenium team. – jabbett Commented Mar 19, 2013 at 14:46
  • I'm observing the same behavior, but despite the timeout error, my script will then continue – Dexygen Commented May 13, 2013 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.#bar. However, Selenium will accept url hashes if the hash is followed by a forward-slash, i.e. https://foo.#/bar. – Walter Roman Commented Mar 31, 2015 at 5:14
Add a ment  | 

3 Answers 3

Reset to default 5

In Selenium IDE simply use the 'storeEval' mand, 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) mand, and the rest of your cases changing the hash using the storeEval mand.

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'");

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())

本文标签: javascriptHow to open a URL with a hash using SeleniumStack Overflow