Created
February 29, 2012 14:45
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use with: