Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlrobinson/4279483 to your computer and use it in GitHub Desktop.
Save tlrobinson/4279483 to your computer and use it in GitHub Desktop.
# Waits for an element to be present, then returns it.
browser.waitForAndGetElementBy = (kind, value) ->
@["waitForElementBy#{kind}"](value, 5000)
.then =>
@["elementBy#{kind}"](value)
browser.init(desired)
.then ->
browser.get "http://example.com/"
.then ->
browser.waitForAndGetElementBy "XPath", "//div[@id='some_id']/div/div/a"
.then (element) ->
browser.clickElement element
.then (element) ->
browser.waitForAndGetElementBy "CssSelector", 'iframe[src^="http://example.com/share"]'
.then (element) ->
browser.frame 0
.then ->
browser.waitForAndGetElementBy "Name", "message"
.then (element) ->
browser.type element, "hello world"
.then ->
browser.waitForAndGetElementBy "ClassName", "share-button"
.then (element) ->
browser.clickElement element
.then ->
browser.windowHandles()
.then (handles) ->
browser.window "Log In | Facebook"
console.log handles
.then ->
browser.waitForAndGetElementBy "Id", "email"
.then (element) ->
browser.type element, FACEBOOK_USER_EMAIL
.then ->
browser.waitForAndGetElementBy "Id", "pass"
.then (element) ->
browser.type element, FACEBOOK_USER_PASSWORD
.then ->
browser.waitForAndGetElementBy "Id", "loginbutton"
.then (element) ->
browser.clickElement element
.then ->
console.log "Quitting"
browser.quit()
, (err) ->
console.log "Error: #{err}"
browser.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment