我用ruby脚本练习写从登陆到选择某些项之后,最后做提交操作,之前跑起来都顺利

Python016

我用ruby脚本练习写从登陆到选择某些项之后,最后做提交操作,之前跑起来都顺利,第1张

如果是弹出窗口页的话需要先把焦点转到这个窗口。

      ##

      #A helper method to wait the popup window to be closed

      #

      def wait_close_popup_window

        i=0

        while page.driver.browser.window_handles.size > 1

          sleep 0.3

          i = i+0.3

          if i > 3

            break

          end

        end

      end

      ##

      #A helper method to wait the popup window to be opened

      #

      def wait_open_popup_window

        i=0

        while page.driver.browser.window_handles.size < 2

          sleep 0.3

          i = i+0.3

          if i > 3

            break

          end

        end

      end

      

      ##

      #A helper method to simplify the operation of popup window

      #     AdminBase.popup_window{

      #       page.execute_script "window.close()"

      #     }

      #

      def popup_window

        wait_open_popup_window

        popup = page.driver.browser.window_handles.last

        within_window(popup) do

          yield

          wait_close_popup_window

        end

      end

      

把你需要在弹窗也处理的代码块替换yield就行了。

1、ruby的意思:n.红宝石深红色adj.红宝石的红宝石色的

2、ruby的读音:英[ˈruːbi]美[ˈruːbi]

3、[例句]The crown was set with precious jewels ─ diamonds, rubies and emeralds.王冠上镶嵌着稀世珍宝——有钻石、红宝石、绿宝石

4、复数:rubies