0

I have the following situation: - a div (that is a button) with an "id" that is always changing; - this div has a inside with a text. Please see below the sample code;

<div id="00NU0000002si99" class="item unused">
  <span>Button Name</span>
</div>

The only way to for my next scenarios to work is to get the "id" for the div. I have tried this:

@browser.div(:text, "Button Name").id

It seems that I am doing something wrong because the line above is returning nothing. Is there a way to get value for this tag?

Cristian M
  • 357
  • 1
  • 3
  • 18
  • is it possible to get the element at least once, in the beginning? – Slavic Jan 03 '12 at 09:01
  • Firstly, why do you need to get the ID of the element? what is it you hope to do with that ID once you have it? Are you just hoping to use that as some way to identify the element and work with it? Secondly see the answers to this SO question http://stackoverflow.com/q/8666822/409820 and the answers (all three) to this question also http://stackoverflow.com/q/8330926/409820 – Chuck van der Linden Jan 03 '12 at 21:49

1 Answers1

0

What is your 'next scenario'? What are you trying to do?

Given that exact HTML you can address that specific div in one of at least two ways

browser.div(:class => 'item unused', :text => 'Button Name')

or

browser.span(:text => 'Button Name').parent

See also the SO questions and their answers, which I linked in my comment above.

If for some strange reason you really need to get the ID (I'm having a difficult time imagining why ) then try

browser.div(:class => 'item unused', :text => 'Button Name').attribute_value('id')
Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43