Skip to content

Instantly share code, notes, and snippets.

@kulor
Created February 29, 2012 14:45
Show Gist options
  • Save kulor/1941289 to your computer and use it in GitHub Desktop.
Save kulor/1941289 to your computer and use it in GitHub Desktop.
Find out if an element can be navigated to using the tab key
module Tabbable
def tagNames
['a', 'button', 'input', 'select', 'textarea', 'object']
end
def selectors
['tabindex']
end
def tabbableCssExpression
tagNames.join(', ') + ' ' + selectors.collect{|selector| "*[#{selector}]"}.join(', ')
end
def tabbable
return @cachedTabbableElements unless @cachedTabbableElements.nil?
@cachedTabbableElements = all(tabbableCssExpression)
end
def tabbable? el
el.native.send_keys :tab
return true if el.text == page.driver.browser.switch_to.active_element.text
false
end
end
@kulor
Copy link
Author

kulor commented Feb 29, 2012

Use with:

World(Tabbable)
puts tabbable? page.find('#myDiv')
puts directlyTabbable? page.find('#myDiv')
puts tabbable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment