• QTP常用function 老古董


    贴一些工作里经常用到的。

    ——不建议专门学习QTP,web自动化有更好的工具,client自动化。。现在没多少做client的项目了。。so——

    ‘检查客户端是否启动,等待n秒

    Function Open_(n)

        If Window("XX终端").Exist Then
            wait(n)
        else
            msgbox "启动失败"
            Exitrun
        End If

    End Function

    ’另存为

    Function sava_as()
        If Dialog("确认另存为").Exist(2) then
            Dialog("确认另存为").Activate
            Dialog("确认另存为").WinButton("是(Y)").Click
        end if
        wait(1)
        closenotpad()
    End Function

    ‘关闭notepad(猜猜为啥用到这个,提醒下:.xls)

    Function closenotpad()
        
        Window("Notepad++").Activate
        wait(1)
        set WshShell = CreateObject("WScript.Shell")
        WshShell.SendKeys "^w"

    End Function

    ’同款系列

    Function KillXxxxProcess()
        on error resume Next
        CreateObject("WScript.Shell").Run "taskkill /f /im excel.exe "
        'CreateObject("WScript.Shell").Run "taskkill /f /im notepad++.exe"
        CreateObject("WScript.Shell").Run "taskkill /f /im Wscript.exe"
    End Function

    ‘继续.xls

    Function save(file_name)

       Dim WshShell
        set WshShell = CreateObject("WScript.Shell")

       Do
        Window("工作簿1").Close
        Do
            'Window("工作簿1").Window("Microsoft Excel").Activate
            WshShell.SendKeys "{Enter}"
            wait(1)
        Loop While Window("工作簿1").Window("Microsoft Excel").Exist(1)
        Window("工作簿1").Dialog("另存为").WinEdit("Edit").Set file_name
        Window("工作簿1").Dialog("另存为").WinButton("保存(S)").Click
        save_as()
        wait(1)
    Loop Until Window("工作簿1").WinObject("工作簿1").Exist(1) = False
    End Function

    ’坐标硬操作

    Set dict=CreateObject("scripting.Dictionary")
    dict.RemoveAll
    dict.Add "1","18"
    dict.Add "2","5"
    dict.Add "3","7"
    dict.Add "4","4"
    dict.Add "5","1"

    line_y_add = 20

    For key_a = 1 to 2
        len_b = int(dict.item(cstr(key_a)))
        
        Window("金融终端").SwfObject("QuoteSequence").SwfObject("treeList").Click 10,-10+line_y_add*key_a

            'For key_b = 0 to len_b
            realy_n = 1550
            For key_b = 0 to 1

                Window("金融终端").SwfObject("QuoteSequence").SwfObject("treeList").Click 60,30+line_y_add*key_b
                check_in_ticker_symobol

            Next
        Window("金融终端").SwfObject("QuoteSequence").SwfObject("treeList").Click 10,-10+line_y_add*key_a

    Next

    ‘多次尝试

    Function saveclick(file_name,i)
            Dim try_num
                try_num = 0
            download i,try_num

            If Window("金融终端").Dialog("另存为").WinEdit("Edit").Exist(1) Then    
                If  Window("金融终端").Dialog("另存为").WinEdit("Edit").GetROProperty("regexpwndtitle") = "name.xls" Then
                    Window("金融终端").Dialog("另存为").WinEdit("Edit").Set file_name
                    Window("金融终端").Dialog("另存为").WinButton("保存(S)").Click
                else
                    Window("金融终端").Dialog("另存为").Close
                    saveclick file_name,i
                End If
            Else
                Set f = fs.CreateTextFile(LogFile, True)  
                f.WriteLine file_name+",下载失败"
                f.Close
            End If

    End Function

    ’从DataTable逐行获取值

    Dim row_count,ticker_id,time_id
    row_count = DataTable.GetSheet("Action1").GetRowCount
    'msgbox row_count
        For j = 1 to row_count
            ticker_id = DataTable.GetSheet("Action1").GetParameter("代码").ValueByRow(j)
            'msgbox ticker_id
            time_id = DataTable.GetSheet("Action1").GetParameter("时间").ValueByRow(j)

      ‘TODO

     Next

  • 相关阅读:
    每日日报
    每日日报
    每日日报
    线上问题定位---jstack
    8.18Java入门--->第二十二节(ObjectOutputStream、ObjectInputStream)
    8.17Java入门--->第二十一节(IO流)
    Mybatis--->第六节一对多和多对一
    8.14Java入门--->第二十节
    8.13Java入门--->第十九节(Map嵌套)
    Java学习
  • 原文地址:https://www.cnblogs.com/ylpb/p/9071011.html
Copyright © 2020-2023  润新知