TurboCoder
TurboCoder

Reputation: 1011

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.

Upvotes: 0

Views: 1634

Answers (1)

Marc Etienne
Marc Etienne

Reputation: 36

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

Upvotes: 2

Related Questions