do you happen to know if there is a way to define both elements and locators using string or symbol interpolation while using the site-prism gem?
I’m trying to do something like this:
0.upto(@adults) do {
element :"adult#{index}", "#passenger-first-name-#{index}"
element :"adult#{index}", "#passenger-last-name-#{index}"
index+=1
}
But I’m getting the following syntax error at executing:
syntax error, unexpected tSYMBEG, expecting keyword_do or ‘{‘ or ‘(‘ (SyntaxError)
element :”adult#{index}” , “#passenger-first-name-#{index}”
I was reading here that symbols DO allow interpolation: http://www.robertsosinski.com/2009/01/11/the-difference-between-ruby-symbols-and-strings/
Maybe I am missing something? Thanks a lot!
I haven’t tried symbol interpolation, but the string interpolation should work. But, you many not need to do that… usually, this sort of thing can be solved by more closely modelling your website using sections. Instead of dynamically creating elements, you could use the
elementsorsectionsmethods that will create arrays of elements. Here’s what I’d do based the example you’ve given:I’m guessing from your example that your website lists passengers… if each passenger is displayed in a separate div then you could consider something like:
Given the above, you could refer to the list of passengers as an array:
I don’t know if that helps, or if it’s possible with your website, but it might point you in the right direction…