Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

ajax - Watir: Need to double click on an element to open custom popup

I am a newbie in WATIR. The problem I am facing is - The application I am testing has thumbnails (like Windows icons) placed on the page and I need to double click it. On doing that, an custom popup (ajax popup implemented in javascript) will open. The fire_event("ondblclick") is not working for me. I also tried 'click' twice but that too is not helping. Is there any other way of handling this? Your help is highly appreciated.

Added 6 July 2010:

I solved it but I have another query now.

Below was the HTML for which I was able to solve using "@ie.div(:class,'GridElementInlineIE').fire_event('ondblclick') "


<div class="gridViewItem" style='display: inline-table;' ondblclick='openAsset("634119577077187500", "", "LIBRARY_ASSETS_TAB", "1", "A111");'
        id='GridComponent634119577077187500'>
        <table style="display: inline-table;" class="gridViewItemTable" cellpadding="0" cellspacing="0"
            onclick="highlightAsset(this, event)" projectid="" dmguid="634119577077187500"
            id="_thumb_634119577077187500" objectclass="VIDEO">
            <tr>
                <td style="padding: 10px 10px 0px 7px">
                    <img class="assetListGridImage draggableThumbnail" id="thumb_634119577077187500"
                        title="A111" alt="A111"
                        src="/images/wait.gif" dmguid="634119577077187500" projectid=""
                        objectclass="VIDEO" _onclick="highlightAsset(this, event)" />
                </td>
            </tr>
            <tr>
                <td style="padding: 0px 0px 0px 7px">

                    A111
                </td>
            </tr>
            <tr>
                <td style="padding: 0px 0px 5px 7px; min-height: 33px; max-height: 33px; height: 33px;">
                    <img alt='Not starred' name='IMAGE634119577077187500' title='Star this asset' src='/Images/star_off.png' onclick='toggleStar(event, this, "634119577077187500")' class='starGrid' />
                    <img alt='video' title='video' src='/Images/asset_type/VIDEO.png'/>
                    <img src='/images/shared.png'  title ='Shared' alt='Shared' />
                </td>

            </tr>
        </table>
    </div>

Now I need to double click on this item (code below). But even though the element is being identified (highlighted with a yellow), the double click is not working. I am trying "@ie.div(:class,'gridViewItem').fire_event('ondblclick')". I've also tried the while loops and click-twice options to no effect. I'm using Watir 1.6 with Ruby186-27_rc2.

           div class="GridElementInline">
                <table class="GridElementInline" style="border: solid 2px #1e606e;min-height:134px;height:134px;max-height: 134px" onclick="highlightAsset(this, event)"
                                                projectid='' folderid="2383" id="_tblBinlist2383" title = "today">
                    <tr>
                        <td style="padding: 10px 10px 0px 7px;">
                            <table id='tblBinlist2383' folderid='2383' projectId='' _onclick='highlightAsset(this, event)' ondblclick='showBinDetails("2383", "")' class='binThumbnail GridElementInline' cellpadding='0' cellspacing='0'><tr><td><img class='fourGridViewImage' src='http://stream.....' /></td><td><img class='fourGridViewImage' src='http://stream.....' /></td></tr><tr><td><img class='fourGridViewImage' src='http://stream.....' /></td><td><img class='fourGridViewImage' src='http://stream.....' /></td></tr></table>
                        </td>
                    </tr>
                <tr>
                <td colspan="2" align="center" style="padding: 10px 10px 0px 7px; font-size: 9px;white-space: nowrap;">
                <div align="left" title="today">
                    today
                </div>
                </td>
                </tr>
                </table>
            </div>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There's one elegant solution I did for Watir 1.6.7 in Windows.

I went to ruby/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/element.rb (your path may change, but the main idea is to access the watir library and modify the element.rb file).

I added these lines:

def fire_event_no_wait(event)
  assert_exists
  assert_enabled
  highlight(:set)
  element = "#{self.class}.new(#{@page_container.attach_command}, :unique_number, #  {self.unique_number})"
  ruby_code = "require 'rubygems';" <<
          "require '#{File.expand_path(File.dirname(__FILE__))}/core';" <<
          "#{element}.fire_event("#{event}")"
  system(spawned_click_no_wait_command(ruby_code))
  highlight(:clear)
end

this will create a method called fire_event_no_wait that behaves just like click_no_wait in watir.

Hope this helps anyone out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...