I've got the following element texts in two labels of an object I need to find with SitePrism:
Is it possible to find such an element by using a case insensitive expression in SitePrism? I was trying the following but I'm getting an error:
element :correct_date, :field, "/correct date/i"
ERROR: Unable to find field "/correct date/i" (Capybara::ElementNotFound)
The expression above even fails when it's an exact match, for whatever reason :S Any idea what I could try?
Short answer : No
Longer answer: The Capybara locators (which is what the string associated with the selector type of :field is) are strings and do not accept regexps. This is because they are implemented via XPath and most (if not all) browsers only support XPath 1.0 so there is no regex support there. Most selector types do support the :text
option but that is applied to the result element, not to any other elements that may be used to find the result element (in this case it would apply to the field element not the label). So if you were looking for the actual label elements you could do
element :correct_date_label, :label, nil, text: /correct_date/i
One potential way to get what you want is to just use an xpath selector, either using the current Capybara selectors to help or writing your own custom XPath that would match both case versions, something along the lines of
element :correct_date, :xpath, (Capybara::Selector.all[:field].call('Correct date') + Capybara::Selector.all[:field].call('correct date')).to_s # might need to be | instead of +
or
element :correct_date, :xpath, ".//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')][./@id = //label[(contains(normalize-space(string(.)), 'Correct date') or contains(normalize-space(string(.)), 'correct date'))]/@for] | .//label[(contains(normalize-space(string(.)), 'Correct date') or contains(normalize-space(string(.)), 'correct date'))]//.//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]"
but that's starting to get a bit complicated