Search code examples
vbscriptqtpsendkeys

vbscript sendkeys works only once after system restart


I have a weird situation here and I am not able to find out the reason and fix.

I have written a script using HP UFT 11.52 for testing a .net web application on IE8

Here is the code:

If Browser(x).Page(x).Frame(x).WebEdit(abc).Exist(0) Then
    Browser(x).Page(x).Frame(x).WebEdit(abc).Click
    Set objSSN=Createobject("Wscript.Shell")
    objSSN.SendKeys" "
    Set objSSN=Nothing
    Browser(x).Page(x).Frame(x).WebEdit(abc).Object.Focus()
    Browser(x).Page(x).Frame(x).WebEdit(abc).Set 100-10-1000
End If

This code runs fine when I run the script after starting my windows laptop. If I run the same code the second time, the code will not enter the space and so does not enter the SSN. Now entering a space is required since clicking the webedit will result in a blank selection, so if I enter something with script it gives incorrect data.

My teammate who works on a virtual machine for running these scripts had no issues running this script on his machine. So I suspect there is some setting either in IE or windows somewhere which needs to be modified.

Can anyone help me identifying the issue.


Solution

  • Instead of sending a space try changing the replay type to device and then Set a space

    If Browser(x).Page(x).Frame(x).WebEdit(abc).Exist(0) Then
        Setting.WebPackage("ReplayType") = 2 
        Browser(x).Page(x).Frame(x).WebEdit(abc).Set " " ' This may not be needed
        Browser(x).Page(x).Frame(x).WebEdit(abc).Set "100-10-1000"
        Setting.WebPackage("ReplayType") = 1 
    End If