module Playwright::LocatorUtils
def escape_for_attribute_selector(text, exact)
-
text
(String
) --
def escape_for_attribute_selector(text, exact) : this should actually be scape(value).replace(/\\ /g, ' ') ver, our attribute selectors do not conform to CSS parsing spec, e escape them differently. = text.gsub(/\\/) { "\\\\" }.gsub(/["]/, '\\"') ct {_text}\"" {_text}\"i"
def escape_for_attribute_selector_or_regex(text, exact)
-
text
(Regexp|String
) --
def escape_for_attribute_selector_or_regex(text, exact) t.is_a?(Regexp) x = JavaScript::Regex.new(text) regex.source}/#{regex.flag}" pe_for_attribute_selector(text, exact)
def escape_for_regex(text)
-
text
(String
) --
def escape_for_regex(text) sub(/[.*+?^>${}()|\[\]\\]/) { "\\#{$&}" }
def escape_for_text_selector(text, exact)
-
text
(Regexp|String
) --
def escape_for_text_selector(text, exact) t.is_a?(Regexp) x = JavaScript::Regex.new(text) rn "/#{regex.source}/#{regex.flag}" ct ext.to_json}s" ext.to_json}i"
def get_by_alt_text(text, exact: false)
def get_by_alt_text(text, exact: false) locator(get_by_alt_text_selector(text, exact: exact)) end
def get_by_alt_text_selector(text, exact:)
def get_by_alt_text_selector(text, exact:) _attribute_text_selector('alt', text, exact: exact)
def get_by_attribute_text_selector(attr_name, text, exact: false)
def get_by_attribute_text_selector(attr_name, text, exact: false) nal:attr=[#{attr_name}=#{escape_for_attribute_selector_or_regex(text, exact)}]"
def get_by_label(text, exact: false)
def get_by_label(text, exact: false) locator(get_by_label_selector(text, exact: exact)) end
def get_by_label_selector(text, exact:)
def get_by_label_selector(text, exact:) nal:label=#{escape_for_text_selector(text, exact)}"
def get_by_placeholder(text, exact: false)
def get_by_placeholder(text, exact: false) locator(get_by_placeholder_selector(text, exact: exact)) end
def get_by_placeholder_selector(text, exact:)
def get_by_placeholder_selector(text, exact:) _attribute_text_selector('placeholder', text, exact: exact)
def get_by_role(role, **options)
def get_by_role(role, **options) locator(get_by_role_selector(role, **(options.compact))) end
def get_by_role_selector(role, **options)
def get_by_role_selector(role, **options) = [] udeHidden: -> (value) { ['include-hidden', value.to_s] }, : -> (value) { ['name', escape_for_attribute_selector_or_regex(value, options[:exact])]}, ked bled cted nded udeHidden l sed do |attr_name| ptions.key?(attr_name) tr_value = options[attr_name] ops << (ex[attr_name]&.call(attr_value) || [attr_name, attr_value.to_s]) props.map { |k, v| "[#{k}=#{v}]"}.join('') nal:role=#{role}#{opts}"
def get_by_test_id(test_id)
def get_by_test_id(test_id) test_id_attribute_name = ::Playwright::LocatorUtils.instance_variable_get(:@test_id_attribute_name) locator(get_by_test_id_selector(test_id_attribute_name, test_id)) end
def get_by_test_id_selector(test_id_attribute_name, test_id)
def get_by_test_id_selector(test_id_attribute_name, test_id) nal:testid=[#{test_id_attribute_name}=#{escape_for_attribute_selector_or_regex(test_id, true)}]"
def get_by_text(text, exact: false)
def get_by_text(text, exact: false) locator(get_by_text_selector(text, exact: exact)) end
def get_by_text_selector(text, exact:)
def get_by_text_selector(text, exact:) nal:text=#{escape_for_text_selector(text, exact)}"
def get_by_title(text, exact: false)
def get_by_title(text, exact: false) locator(get_by_title_selector(text, exact: exact)) end
def get_by_title_selector(text, exact:)
def get_by_title_selector(text, exact:) _attribute_text_selector('title', text, exact: exact)