tags:

views:

71

answers:

2

I am having any issue with selecting any item from the drop down. Below is the HTML from our site. The HTML looks like this

<div class="x-form-field-wrap x-trigger-wrap-focus" 
id="ext-gen157" style="width: 170px;"><input type="hidden" 
id="parentEntity" name="parentEntity" value=""><input type="text" 
id="cmbParentEntityId" autocomplete="off" size="24" class=" 
x-form-text x-form-field x-form-focus" style="width: 145px;">
<img class="x-form-trigger x-form-arrow-trigger" 
src="../ext/resources/images/default/s.gif" id="ext-gen158"></div>

So I have created a watir code which looks like this:

@browser.text_field(:id,"cmbParentEntityId").set("1")

which search for all the accounts starting with 1.Once the value is set to 1, the drop down is showing only accounts starting with 1. Below is the HTML code from the drop down

 <div class="x-combo-list-inner" id="ext-gen336" style="width: 
248px; overflow: auto; height: 40px;"><div class="x-combo-list-item  
x-combo-selected">10_12_2010</div><div 
class="x-combo-list-item ">10_13_2010</div></div>

Based on the above code I have created the Watir code

@browser.div(:class => "x-combo-list-inner", :text => "10_12_2010").click

But nothing is happening, I have searched the web but couldn't find any answers, I really appreciate that if anyone can help me to point to right direction.

Thanks

+1  A: 

My guess is that some JavaScript event should be explicitly fired. See How to find out which JavaScript events fired?

Željko Filipin
Yes,It was related to JavaScript event and the link you provided was quite helpful.
QA Geeks
Feel free to vote up my answer then. :)
Željko Filipin
+1  A: 

What do you mean that nothing is happening? If i try the code provided by you, then i'll get an expected UnknownObjectException:

irb(main):003:0> b.div(:class => "x-combo-list-inner", :text => "10_12_2010").click
Watir::Exception::UnknownObjectException: Unable to locate element, using {:class=>"x-combo-list-inner", :text=>"10_12_2010"}
        from c:/Ruby/lib/ruby/gems/1.8/gems/watir-1.6.6/lib/watir/element.rb:57:in `assert_exists'
        from c:/Ruby/lib/ruby/gems/1.8/gems/watir-1.6.6/lib/watir/element.rb:315:in `enabled?'
        from c:/Ruby/lib/ruby/gems/1.8/gems/watir-1.6.6/lib/watir/element.rb:62:in `assert_enabled'
        from c:/Ruby/lib/ruby/gems/1.8/gems/watir-1.6.6/lib/watir/element.rb:259:in `click!'
        from c:/Ruby/lib/ruby/gems/1.8/gems/watir-1.6.6/lib/watir/element.rb:229:in `click'
        from (irb):3

That is because you're trying to find a div element with a class of "x-combo-list-inner" and a text of "10_12_2010". There isn't such an element. See this:

irb(main):007:0> b.div(:class => "x-combo-list-inner").text
=> "10_12_2010\r\n10_13_2010"

Text of "x-combo-list-inner" includes texts for every child element. You could search for that particular child element like this:

irb(main):008:0> b.div(:class => "x-combo-list-inner").div(:text => "10_12_2010").html
=> "\r\n<DIV class=\"x-combo-list-item  &#13;&#10;x-combo-selected\">10_12_2010</DIV>"

Or with regexps:

irb(main):009:0> b.div(:class => "x-combo-list-inner", :text => /10_12_2010/).text
=> "10_12_2010\r\n10_13_2010"

And when it comes to clicking then you have to know which exact div you need to click - is it the first one, or the second one. Also, if nothing happens then you have to find out what JavaScript events are binded to these elements exactly and then fire events manually:

irb(main):010:0> div = b.div(:class => "x-combo-list-inner").div(:text => "10_12_2010")
=> #<Watir::Div:0x5846088 located=false how={:text=>"10_12_2010"} what=nil>
irb(main):013:0> div.fire_event("onmousedown")
=> nil
irb(main):014:0> div.fire_event("onmouseup")
=> nil
Jarmo Pertman
Thanks so much for providing the valuable help. I was able to solve the problem once i figured out the javaScript event and correct element.
QA Geeks
Thanks so much for providing the valuable help. I was able to solve the problem once i figured out the javaScript event and correct element.
QA Geeks