2

私はWATIRの初心者です。私が直面している問題は、テストしているアプリケーションのサムネイル (Windows アイコンなど) がページに配置されており、それをダブルクリックする必要があることです。そうすると、カスタム ポップアップ (javascript で実装された ajax ポップアップ) が開きます。fire_event("ondblclick") が機能しません。「クリック」も2回試しましたが、それも役に立ちません。これを処理する他の方法はありますか?あなたの助けは非常に高く評価されています。

2010 年 7 月 6 日追加:

解決しましたが、別のクエリがあります。

以下は、「@ie.div(:class,'GridElementInlineIE').fire_event('ondblclick')」を使用して解決できた HTML です。


<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>

次に、このアイテムをダブルクリックする必要があります (以下のコード)。ただし、要素が識別されている (黄色で強調表示されている) 場合でも、ダブルクリックは機能しません。「@ie.div(:class,'gridViewItem').fire_event('ondblclick')」を試しています。また、while ループとクリック 2 回のオプションを試してみましたが、効果がありませんでした。Ruby186-27_rc2 で Watir 1.6 を使用しています。

           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>
4

2 に答える 2

1

Windows の Watir 1.6.7 に対して私が行ったエレガントなソリューションが 1 つあります。

ruby/lib/ruby/gems/1.8/gems/watir-1.6.7/lib/watir/element.rb に移動しました (パスは変更される可能性がありますが、主なアイデアは、watir ライブラリにアクセスして element.rb を変更することです)ファイル)。

これらの行を追加しました:

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

これにより、watir の click_no_wait と同じように動作する fire_event_no_wait というメソッドが作成されます。

これが誰にも役立つことを願っています。

于 2011-04-15T20:58:28.837 に答える
0

編集あなたは今ここでこのコードのより良い、動作するバージョンを得ることができます。

これで本当に行き詰まった場合に備えて、すばやく少し汚い回避策を示します。これにより、相対的なハードウェアの自動クリックが保証され、クリックイベントで発生する問題が保存されます(従来、一部のコーナーケースでは問題が発生していました)。

これを「mouseControl.rb」というファイルに貼り付けてから、require'mouseControl'を使用してメインファイルからリンクします。使ってから久しぶりですが、ダブルクリックでハックできると思います。このファイルが機能する(または少なくとも機能する)ことを知っているので、このハックは含めませんでした。'win32ole'が必要になります。セットアップが完了したら、@ browser.button(:text、 "boo")。left_clickのように簡単に言うことができ、トップレイヤーのハードウェアを手動でクリックできます。

あなたがより良い答えを得ることができるまであなたを乗り越えるべきです。

require 'watir'

module Watir
  class Element
    def top_edge
      assert_exists
      assert_enabled
      ole_object.getBoundingClientRect.top.to_i
    end

    def top_edge_absolute
      top_edge + page_container.document.parentWindow.screenTop.to_i
    end

    def left_edge
      assert_exists
      assert_enabled
      ole_object.getBoundingClientRect.left.to_i
    end

    def left_edge_absolute
      left_edge + page_container.document.parentWindow.screenLeft.to_i
    end

    def left_click
      x = left_edge_absolute + 1
      y = top_edge_absolute + 1
      #puts "x: #{x}, y: #{y}"
      WindowsInput.move_mouse(x, y)
      WindowsInput.left_click
    end

    def right_click
      x = left_edge_absolute
      y = top_edge_absolute
      #puts "x: #{x}, y: #{y}"
      WindowsInput.move_mouse(x, y)
      WindowsInput.right_click
    end
  end
end 


module WindowsInput
  # Windows API functions
  SetCursorPos = Win32API.new('user32','SetCursorPos', 'II', 'I')
  SendInput = Win32API.new('user32','SendInput', 'IPI', 'I') 
  # Windows API constants
  INPUT_MOUSE = 0 
  MOUSEEVENTF_LEFTDOWN = 0x0002 
  MOUSEEVENTF_LEFTUP = 0x0004 
  MOUSEEVENTF_RIGHTDOWN = 0x0008 
  MOUSEEVENTF_RIGHTUP = 0x0010 

  module_function

  def send_input(inputs) 
    n = inputs.size 
    ptr = inputs.collect {|i| i.to_s}.join # flatten arrays into single string 
    SendInput.call(n, ptr, inputs[0].size) 
  end

  def create_mouse_input(mouse_flag) 
    mi = Array.new(7, 0) 
    mi[0] = INPUT_MOUSE 
    mi[4] = mouse_flag 
    mi.pack('LLLLLLL') # Pack array into a binary sequence usable to SendInput 
  end 

  def move_mouse(x, y)
    SetCursorPos.call(x, y)
  end

  def left_click
    leftdown = create_mouse_input(MOUSEEVENTF_LEFTDOWN) 
    leftup = create_mouse_input(MOUSEEVENTF_LEFTUP) 
    send_input( [leftdown, leftup] )
  end

  def right_click
    rightdown = create_mouse_input(MOUSEEVENTF_RIGHTDOWN) 
    rightup = create_mouse_input(MOUSEEVENTF_RIGHTUP) 
    send_input( [rightdown, rightup] )
  end
end
于 2010-07-12T13:48:18.033 に答える