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

后端 未结 2 1302
悲&欢浪女
悲&欢浪女 2020-12-20 02:02

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 do

2条回答
  •  一向
    一向 (楼主)
    2020-12-20 02:32

    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.

提交回复
热议问题