0

For testing with watir it would be much easier if I could refer to elements by Id, however, with knockout, it generates many of the elements itself.

I'm currently using xpath to get to these elements, however, it is.....messy. So it would kind of be good if I could get knockout to autogen IDs.

Is there a way to do this?

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
  • There may be other alternatives to identifing what you want in watir without resorting to xpath.. if you wanted to post a sample of the HTML and indicate how you are currently identifying things.. or how you know when interacting manually where and what you want to interact with, very often the same logic (e.g. 'the buy-now button on the same table row as part number xxzzy') can be used in your watir scripts. (and the result is usually easier to read than xpath) – Chuck van der Linden May 08 '12 at 02:00

1 Answers1

1

There is no way out of the box. However it is easy to implement custom bindings to do what you are asking. How you make them "predicable" and not just unique is up to you to decide I guess.

Here is a related answer that shows how to generate unique Ids.

You can modify this to follow whatever scheme you wish.

Hope this helps.

Community
  • 1
  • 1
madcapnmckay
  • 15,782
  • 6
  • 61
  • 78
  • pretty close, but you'd still have to add a binding to each element, though that's not too bad. – Keith Nicholas May 07 '12 at 21:03
  • 1
    If you want to you could write a binding for the top level element that goes down it's children and gives them ids, avoids having to put it on everything. – madcapnmckay May 07 '12 at 22:59