Class: Selenium::WebDriver::Remote::Bridge::LocatorConverter Private
Relationships & Source Files | |
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/remote/bridge/locator_converter.rb |
Constant Summary
-
ESCAPE_CSS_REGEXP =
# File 'rb/lib/selenium/webdriver/remote/bridge/locator_converter.rb', line 25/(['"\\#.:;,!?+<>=~*^$|%&@`{}\-\[\]()])/
-
UNICODE_CODE_POINT =
# File 'rb/lib/selenium/webdriver/remote/bridge/locator_converter.rb', line 2630
Instance Method Summary
-
#convert(how, what)
Internal use only
Converts a locator to a specification compatible one.
-
#escape_css(string)
private
Internal use only
Escapes invalid characters in CSS selector.
Instance Method Details
#convert(how, what)
Converts a locator to a specification compatible one.
# File 'rb/lib/selenium/webdriver/remote/bridge/locator_converter.rb', line 34
def convert(how, what) how = SearchContext.finders[how.to_sym] || how case how when 'class name' how = 'css selector' what = ".#{escape_css(what.to_s)}" when 'id' how = 'css selector' what = "##{escape_css(what.to_s)}" when 'name' how = 'css selector' what = "*[name='#{escape_css(what.to_s)}']" end if what.is_a?(Hash) what = what.each_with_object({}) do |(h, w), hash| h, w = convert(h.to_s, w) hash[h] = w end end [how, what] end
#escape_css(string) (private)
Escapes invalid characters in CSS selector.
# File 'rb/lib/selenium/webdriver/remote/bridge/locator_converter.rb', line 66
def escape_css(string) string = string.gsub(ESCAPE_CSS_REGEXP) { |match| "\\#{match}" } string = "\\#{UNICODE_CODE_POINT + Integer(string[0])} #{string[1..]}" if string[0]&.match?(/[[:digit:]]/) string end