zoukankan      html  css  js  c++  java
  • Watir Popup 采用新线程进行处理

    require 'watir'
     require 'win32ole'
    $h"A I o T9~o#n*X*~0def check_for_popups(title="Microsoft Internet Explorer", button="OK")51Testing软件测试网0T o A-F e w8q ?
        popup=Thread.new{
    &g7U(j9J,W y0        autoit=WIN32OLE.new('AutoItX3.Control')51Testing软件测试网(d q"k1o;^)p8R
            ret=autoit.WinWait(title,"",60)
    qt.`$o R.o x p D v0       if(ret==1)
    u C5d,\6~,r"|$j0            puts"There is popup."
    3t u L.U Q I.[5l B q0            autoit.WinActivate(title)51Testing软件测试网 w T4x J j t ? v
                button.downcase!51Testing软件测试网 j y l t Y _ g+O
               ifbutton.eql?("ok") || button.eql?("yes") || button.eql?("continue")
    K%K f%D-| \ } L:V!}6J R0                autoit.Send("{Enter}")51Testing软件测试网 U2`7Z i F@
               else51Testing软件测试网 [ Y k z J'i @ D%P
                    autoit.Send("{tab}")
    5j X9m y l L2U T0                autoit.Send("{Enter}")51Testing软件测试网 p)~8N5t6l&m5@
                end
    ;J+H x+R S$j"g:\G0        elsif (ret==0)
    (Q H d/F)N \/J9Z Q I J P0            puts"No popup, please check your code."
    Q w%F S+Q K)j0        end
    (h d!m N C0    }
    )W9| V } J1h k6f0    at_exit {Thread.kill(popup) }
    7o j So!G0end51Testing软件测试网3i ~ n E)P
    51Testing软件测试网 C N!D/z.V l'i,O
    $ie.link(:text,//).click_no_wait51Testing软件测试网.s V+V [ j.a k y ] g:z
    check_for_popups("MicrosoftInternet Explorer","OK")51Testing软件测试网"e u3W O F9Y5X/H }
    这个方法针对 Popup是 OK/cancel之类的弹出框比较有效。

  • 相关阅读:
    0309. Best Time to Buy and Sell Stock with Cooldown (M)
    0621. Task Scheduler (M)
    0106. Construct Binary Tree from Inorder and Postorder Traversal (M)
    0258. Add Digits (E)
    0154. Find Minimum in Rotated Sorted Array II (H)
    0797. All Paths From Source to Target (M)
    0260. Single Number III (M)
    0072. Edit Distance (H)
    0103. Binary Tree Zigzag Level Order Traversal (M)
    0312. Burst Balloons (H)
  • 原文地址:https://www.cnblogs.com/zhangfei/p/2017246.html
Copyright © 2011-2022 走看看