Reputation: 374
I am using the page object Gem with Watir. During testing I found that I have a field that has the same contents that show in the same location but have separate unique ID's. The difference is before you get to the page.
I tried using Xpaths:
select_list(:selectionSpecial, :xpath => "//select[@id='t_id9' OR @id='t_id7']")
But was met with a script error.
They are static ID's but I want to force them into one variable since that would allow me to use "populate_page_with" feature.
I have a long winded way currently, but I am fishing for a more efficient way that works with the page object Features.
Does anyone know of a way to do this?
Upvotes: 1
Views: 249
Reputation: 46846
Your approach of using xpath can work. The problem is the syntax errors in the xpath selector. It should be:
"//select[@id='t_id9' or @id='t_id7']"
Note:
//
rather than a \
or
is case-sensitive; it has to be lower case'
for the first id attributePersonally, I find css and xpath selectors harder to use. I would go with the id locator with a regex. The following gives the same results, but some will find it easier to read.
select_list(:selectionSpecial, :id => /^t_id(7|9)$/)
Upvotes: 1