1

My list is nested under two headers and I don't know how to access them via watir since the style, display is set to "none" until a "hover" event occurs. And the class isn't defined until a hover/mousveover either.

b.link(:text, /Assessments/).fire_event('onmouseover')

will open the initial drop-down. I have no idea how to access the elements in the "sub-level"

Variations on the following are rejected by watir:

b.link(:class, "sub-level").click
b.link(:class, "sub-level").fire_event('onmouseover')
b.link(:class, "sub-level").fire_event('hover')

Watir::Exception::UnknownObjectException: unable to locate element, using {:class=>"sub-level", :tag_name=>"a"}

I've been running this through IRB for quick testing of each new line I add to my script. If this is incorrect, I would appreciate any advice.

<li class="top-level">
<a class="" href="#">
Assessments&nbsp;&nbsp;
<img id="lfArrowImg" style="border:0px;" src="https://test.com/top/images/global_nav_downArrow.gif">
</a>
  <ul style="z-index: 1045; display: none;">
  <li class="sub-level">
     <a class="">
     Assessments
     <div id="menugroup" class="dr-menu-node dr-menu-node-icon rich-menu-item-folder rich-menu-group-folder"></div>
     </a>
  <ul style="z-index: 1068; display: none;">    
  <li class="sub-level">
     <a class="" href="http://test.com/content/aa/assessment/index.xhtml">Main</a>
  </li>
  <li class="sub-level">
  <li class="sub-level">
</ul>
</li>

Thanks, Damien

5
  • 1
    btw: congradulations for posting the 500th Stack Overflow item with a 'watir' tag on it. (no, you don't win anything, other than I hope a good answer to your question. Commented Jan 10, 2012 at 6:12
  • you hope? as long as you answered it, the good part is in the bag. Commented Jan 10, 2012 at 15:32
  • heh not counting that chicken till I see a big green checkmark indicating an accepted answer. I'm not always right, and I'm always learning more (often as a result of researching answers to questions). Although my wife found an expression the other day that is almost perfect.. "often in error, never in doubt" LOL Commented Jan 10, 2012 at 16:38
  • No luck, gentlemen. I can fire off the Top-level Assessment link which will display a list. Trying to access anything on the list is a problem. And 'li' is expecting a hash. b.li(:class, 'sub-level', :text, 'Assessments').link.click ArgumentError: expected Hash or (:how, 'what'), got [:class, "sub-level", :text, "Assessments"] from C:/Ruby/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.4.1/lib/watir-webdriver/container.rb :26:in extract_selector' from C:/Ruby/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.4.1/lib/watir-webdriver/elements/generated.rb:1769:in li' Commented Jan 12, 2012 at 18:41
  • You are not expressing the hash correctly. Compare what you wrote above to what I gave in my answer. You have put commas between the name and the value. You need to separate the name and value with => and then put commas between the name => value groups. b.li(:class => 'sub-level', :text => 'Assessments').link.click Commented Jan 14, 2012 at 0:59

1 Answer 1

2

The error is correct since you have no link tag in that code with a class of sub-level. The things with that class are li (List Item) elements which contain link elements (aka 'anchor' hence the a tag)

Try something like this (depending on which link you want to click)

browser.li(:class => 'sub-level', :text => 'Assessments').link.click
browser.li(:class => 'sub-level', :text => 'Main').link.click

For more on ways to identify elements, especially if they do not have a handy ID, Class etc, see the answers to this SO question: How to get index of parent element using Watir Webdriver? and the answers (all three) to this question also: Accessing an element with no attributes in Watir

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.