No need to be sorry, and I fully understand the 'revert to what I
know' aspect of this when learning something new.
So can you share some of the appropriate HTML for these tabs, and what
you need to do with them?
It may be that a for loop would be your best solution, but there might
also be some much better ways around this.
Ruby is really good about allowing you to easily iterate on arrays,
hashes, arrays of objects, etc. and the latest versions of watir and
watir-webdriver are great about being able to return collections of
elements that have something in common, or from within some other
element.
For example if tabs are done as divs of a given class inside which are
links, and they are all inside some other container, you can get all
of them into a nice package via something like
tabs = browser.div(:id, 'tabholder').divs(:class, 'tab')
Then if you wanted to loop through and do something with each of those
tabs, you could do something like
tabs.each do |tab|
puts tab.text
tab.link.click
assert browser.div(:id, 'group_title').text.contains? tab.text
end
See where I'm going?
If you need the index of the element in the array, then you can
use .each_with_index, and it will take care of all the index value
overhead That could be useful if you just want to make an array out
of something from each tab
tabs.each_with_index do |tab, i|
tab_titles[i] = tab.text
tab_links[i] = tab.link.url
end
(those here better with Ruby than I, wack me if I got any of that
wrong)
On Oct 20, 6:48 pm, Joe Fleck <[email protected]> wrote:
> I know. Sorry.
>
> Here is what I am trying to accomplish.
>
> Our app has communities that professional members belong to so they
> can communicate with one an other.
>
> Within these communities there are tabs and the community could have 2 to 5
> or even more showing. My test is to click on each one of them and make sure
> the user lands on the intended page. What I have done so far is retrieved
> the tab names from html list they are in. I have this hole process in a 'do
> loop' though when the script completes the first tab but blows up when it
> moves on to the next one. I feel if I put the array into a string then use
> the split method in Ruby I might be able to do a better job of control the
> outcome. I am a long time QTP developer so WATIR, ruby are very new to me.
> I have always used for...next statements in VBScript because I feel I can do
> a better job of control the script.
>
> I hope this helps.
>
> Thank you,
> Joe
> On Thu, Oct 20, 2011 at 4:49 PM, Chuck van der Linden <[email protected]>wrote:
>
>
>
>
>
>
>
> > um, you want to take something that is basically an array, cram it all
> > into a comma separated string so you can use split to put it back into
> > an array again?
>
> > I'm really confused why you want to do things that way
>
> > Perhaps if you were to explain exactly what it is that you are trying
> > to accomplish (at a slightly higher level) we could suggest a best
> > approach
>
> > it is sort of a 'ruby language' type question, but since it's in the
> > context of dealing with select list options and values, the answer is
> > likely to be of value to the group.
>
> > On Oct 20, 10:28 am, Joe Fl <[email protected]> wrote:
> > > How can take those values from the list and put them in a string so I
> > > can use the split method?
>
> > > the values from the list box are
> > > ACG GI Circle
> > > Advisory Board CDK Sandbox
> > > Advisory Board Sandbox
> > > AFCC
> > > Akron Children's Hospital
> > > Bayer Pulmonary Hypertension Community
> > > Better Health Greater Cleveland
> > > Board of Governors
> > > Case Western Reserve University - School of Medicine Alumni
> > > CHB Demo
> > > Children's Hospital Boston
> > > Children's Hospital Boston Alumni Association Satellite Community
> > > Children's Hospital Boston PPOC Online Community
> > > Covance Virtual Advisory Board
> > > Future Forum
> > > Future Forum Editorial Board
> > > GI Consultant Forum
> > > Janssen Advisory Board Forum
> > > Medical Affairs Leaders Forum
> > > NAPH Member Community
>
> > > I want to place them in a string called com_list with a comma between
> > > each value.
>
> > > I currently retrieve them by above code but it would a lot easier to
> > > work with them in a string.
>
> > > Thank you,
> > > Joe
>
> > > On Oct 19, 3:17 pm, Chuck van der Linden <[email protected]> wrote:
>
> > > > On Oct 19, 11:14 am, Joe Fl <[email protected]> wrote:
>
> > > > > Hi,
>
> > > > > I have figure it out.
>
> > > > > Code...
> > > > > names = $browser.select_list(:name,'communities').options
>
> > > > > community_names_arr = Array.new
>
> > > > > commuName = ""
>
> > > > > name_number = 0
>
> > > > > names.each do |name|
>
> > > > > puts commuName = "#{name_number}: #{name.text}"
>
> > > > > name_number = name_number + 1
>
> > > > > end
>
> > > > > this gives me the text to each option in the listbox.
>
> > > > You might want to make use of .each_with_index to make your code a
> > > > little easier and cleaner
>
> > > > names = $browser.select_list(:name,'communities').options
>
> > > > community_names_arr = Array.new
>
> > > > commuName = ""
>
> > > > names.each_with_index do |name, i|
>
> > > > puts commuName = "#{i}: #{name.text}"
>
> > > > end
>
> > --
> > Before posting, please readhttp://watir.com/support. In short: search
> > before you ask, be nice.
>
> > [email protected]
> >http://groups.google.com/group/watir-general
> > [email protected]<http://groups.google.com/group/watir-generalwatir-general+unsubscribe...>
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
[email protected]
http://groups.google.com/group/watir-general
[email protected]