vbscriptqtphp-uftuft14

QTP/UFT - Include A Select All Text in SendKeys Function


So I have this send keys function:

Code:

Public Function sendKeys(Obj, strParam)
    Wait(1)
    Obj.Click
    Dim shell
    Set shell = CreateObject("WScript.Shell")
    shell.SendKeys strParam
    set shell = Nothing
    Wait(2)
End Function

But what I would like to do is include in this function a way to first select the text in the WebEdit field then enter the data.

At the moment what I do is this:

Code:

call sendKeys( Browser("openurl:= ").Page("url:= ").WebElement("xpath:= "), "^a")
call sendKeys( Browser("openurl:= ").Page("url:= ").WebElement("xpath:= "), "text")

So essentially what I would like to do is combine the above into one statement that performs the select all text and inserts the required text.


Solution

  • Simply, just add a line to your sendkeys function :

    Public Function sendKeys(Obj, strParam)
        Wait(1)
        Obj.Click
        Dim shell
        Set shell = CreateObject("WScript.Shell")
        shell.SendKeys "^a" 'New line
        shell.SendKeys strParam
        set shell = Nothing
        Wait(2) 
    End Function