EBooker
EBooker

Reputation: 374

Make 1 page objects Two Elements ID's to 1 page object Variable

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

Answers (1)

Justin Ko
Justin Ko

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:

  • The start should be a // rather than a \
  • Using or is case-sensitive; it has to be lower case
  • There was also a missing closing ' for the first id attribute

Personally, 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

Related Questions