views:

55

answers:

5

I am attempting to set up some UI testing in Watir for our web application. I'm running into trouble getting the click events to propagate. We are using EXTJS to make tabs, which are spans in the resulting html.

If I select a span like this it works:

span1 = @browswer.span(:text=>"Tab Name")
span1.click

The trouble is when I have a subtab with the same name and want to be able to differentiate them. The only way I've found to select the subtab explicitly is to first select the list that the subtab is in, and then select the subtab from that.

ul = @browser.ul(:class=>/tab-strip-bottom/)
span2 = ul.span(:text=>"Tab Name")
span2.click

span2.click doesn't appear to do anything. The only different (I can see) between span1 and span2 is the container attribute. span1.@container = @browser, span2.@container = ul.

I tried setting the container on span2 with

span2.instance_variable_set("@container", @browser)

but then I wind up clicking on the wrong tab anyway. Any thoughts on this? Thanks!

+1  A: 

Please share the HTML code, I do not even understand the problem.

Maybe you need to fire some JavaScript event. See How to find out which JavaScript events fired?

Željko Filipin
A: 

I finally solved the problem I was having with xpath.

tab = @browser.element_by_xpath(".//*[contains(@class,'x-tab-strip-top')]//*/em/span/span[. =\"#{value}\"]") 
tab.click

It isn't ideal because the xpath code is pretty ugly. If it's possible to select the element by using watir's "candy" selectors, that would be much better for maintainability.

MN Phil
The xpath solution turns out to not be as ugly as I had originally thought. I can use relative xpaths concatenated together in much the same way as the Watir methods allows. So I can have a method that returns the xpath to the tab strip needed, and another to find the xpath for the tab relative to the tab strip) and another to find a menu item (relative to the tab). Slap them together and I've got an absolute xpath to the element in question.
MN Phil
Sometimes that kind of thing may be needed, but in your case I think you can just use Watir as it's designed to be used. embedded_tab = @browser.span(:text => "Tab Name").span(:text => "Tab Name")gives you the embedded Tab. Or even better:parent_tab = @browser.div(:id, 'somethingUnique').span(:text => "Tab Name") child_tab = parent_tab.span(:text => "Tab Name")will always give the parent (non-embedded) tab (replace div with something real) and the child tab relative to that.This removes the need to debug your 3 functions and decrypt the XPath to figure out what your code is doing.
JEH
A: 

You can specify an index to use when there are multiple matching objects. Does this work for you?

@browser.span(:text=>"Tab Name", :index => 2).click

The index values are relative to the container you're searching in. For a table of all possibilities to use when searching for objects see: HTML Elements Supported By Watir

JEH
A: 

As a comparison, does it work when you record the clicks in iMacros for IE or Firefox?

FrankJK
The macro recorders I've tried rely on element ids, most of which are generated by ext (at runtime in the browser), so I don't want to rely on them.
MN Phil
iMacros is very flexible about this, it can look for anything, even an image of a button. But anyway, I see you solved it ;)
FrankJK
A: 

We had a web page menu with multiple tiers, sounds like what you have. The mouse would drop off the second level of the menu while going to the next selection (directly diagonal) and the second menu level would close. Is that what you are talking about? We solved it by firing javascript because the menu items called javascript (Zeljko's solution). We just needed to note the id's of the menu items. Not sure if that is uglier or prettier than the xpath solution. I say "we" because I needed help with that.

Dave McNulla