Pages

Tuesday, March 15

Sendkeys Method - Keyboard Oprations in QTP


Hello Friends!
In this post we'll learn how to perform keyboard operation in QTP using vbscript.

What's the need of Sendkeys?


Hmmm... ok.. Refer the blow code.

Set oShell = CreateObject("WScript.Shell")
SystemUtil.Run "D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Click
oShell.SendKeys "john"
Dialog("text:=Login").WinEdit("attached text:=Password:").Click
oShell.SendKeys "wrong "
Dialog("text:=Login").WinButton("text:=OK").Click

Copy this code in QTP and run it.

Okie.. Now you can see, because we have entered incorrect password, following error dialog will be displayed.






Now we need to close error dialog and enter correct password in the login window.

If do this using DP code, we need to get the properties of error window and write one more line of code.

Dialog("text:=Flight Reservations").WinButton("text:=OK").Click



Instead of addind more objects in our code and writing extra lines for this, we can simply press escape key (ESC) from keyboard and our job is done!!

How can we do that using QTP?


All you need to do is, create a Wscript object and then you can use Sendkeys for that purpose.

Set oShell = CreateObject("WScript.Shell")
oShell.SendKeys "{ESC}"

Done!!


This thing is very useful when application have no automation interface. And it's quite fast as well. Depends on the need.



Most keyboard characters are represented by a single keystroke. Some keyboard characters are made up of combinations of keystrokes (CTRL+SHIFT+HOME, for example).

Please note:-

- To send a single keyboard character, send the character itself as the string argument. For example,
- To send the letter x, send the string argument "x".
- To send a space, send the string " ".
- You cannot send the PRINT SCREEN key {PRTSC} to an application.



Examples:

  • oShell.SendKeys "{ESC}"    - press escape key
  • oShell.SendKeys "john"    - type john
  • oShell.SendKeys "+^{ESC}"    - press Ctrl + Shift + Esc keys (open Windows Task Manager)
  • oShell.SendKeys "%{F}"    - press Alt + F key (open file menu)


For details of all the characters, please refer the following table.



In case of any queries, please post your comments.

33 comments:

  1. i think CTRL & SHIFT characters need to be replaced in the table

    ReplyDelete
  2. no its right...

    ReplyDelete
  3. Its very nice explanation about using keyboard keys in detail.keep up the good work.
    Thank you,
    Krish

    ReplyDelete
  4. How do i do the sendkey for windows button?

    ReplyDelete
    Replies
    1. You can try Ctrl+Esc combination for it...
      i.e. ^{ESC}

      Delete
  5. Hi... I want a shortcut for print screen key on keyboard...While I am {PRTSC},its asking me for a printer than printing the screen..can anyone help me with this issue..

    Thanks in advance

    ReplyDelete
  6. Hi, I am using below script to print the screen in paint, but not working. Can anyone assist me

    Set oShell = CreateObject("WScript.Shell")
    oShell.SendKeys "+^{ESC}"
    Systemutil.Run "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
    oShell.SendKeys "^{PRTSC}"
    Systemutil.Run "D:\WINDOWS\System32\mspaint.exe"
    wait(5)
    oShell.SendKeys "^Set oShell = CreateObject("WScript.Shell")
    oShell.SendKeys "+^{ESC}"
    Systemutil.Run "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
    oShell.SendKeys "^{PRTSC}"
    Systemutil.Run "D:\WINDOWS\System32\mspaint.exe"
    wait(5)
    oShell.SendKeys "^V"

    ReplyDelete
  7. Hi, what is the argumrnt for windows button

    ReplyDelete
  8. How can i SEND CTRL+C??

    ReplyDelete
  9. how to open IE in private mode through qtp

    ReplyDelete
  10. How I can send CTRL + T in mainframe by QTP

    ReplyDelete
  11. Hi,

    i need some more information on Send keys for TAB and ENTER where haing multiple webelements in webtable which are having same propertis

    ReplyDelete
  12. Hi,

    I am using send keys for right click button and then select context menu. but I am unable to run. I want to perform below operation:
    Right click -> Open -> buy.
    I am using send keys {DOWN} and {ENTER}
    Script has been running but next page is not opening.

    ReplyDelete
  13. How do I send a string in WinEdit box using sendkeys??

    ReplyDelete
  14. haii,
    I need sendkey shortcut for windows key

    ReplyDelete
  15. try this alt+space+c

    ReplyDelete
    Replies
    1. What is the shortcut for windows key or F10

      Delete
    2. Unable to type F10 key for automation by VB script. Please let me know

      Delete
  16. đồng tâm
    game mu
    cho thuê nhà trọ
    cho thuê phòng trọ
    nhac san cuc manh
    số điện thoại tư vấn pháp luật miễn phí
    văn phòng luật
    tổng đài tư vấn pháp luật
    dịch vụ thành lập công ty trọn gói
    lý thuyết trò chơi trong kinh tế học
    đức phật và nàng audio
    hồ sơ mật dinh độc lập audio
    đừng hoang tưởng về biển lớn ebook
    chiến thắng trò chơi cuộc sống ebook
    bước nhảy lượng tử
    ngồi khóc trên cây audio
    truy tìm ký ức audio
    mặt dày tâm đen audio
    thế giới như tôi thấy ebook

    nhã hứng của hai vị…” Trình Phi nói chuyện với Lưu Phong so với Chu Cao Phi thì quả nhiên là lễ độ hơn nhiều.

    Chờ đến khi hắn ngẩng đầu lên thì ba người Lưu Phong đã đi được một đoạn.

    Cẩn thận ngẫm nghĩ lại câu nói lúc nãy của Lưu Phong, Trình Phi có chút mệt mỏi, thì thầm tự nói với chính mình: “Làm người thì ai mà chả muốn làm người, có ai muốn làm chó đâu nhưng ta thực sự không có cơ hội làm người…”

    Trình Phi nói câu này Lưu Phong không nghe được, nếu không dám chắc hắn sẽ vỗ vai Trình Phi mà nói: “Cơ hội chính là do mình tranh thủ mà có.” Mặc dù Lưu Phong cũng không biết có đúng là như vậy hay không nhưng muốn khích lệ người khác, ắt phải nói như vậy.

    Cắt đuôi được Trình Phi, Lưu Phong nắm tay Vương Đông Đông và tiểu Linh nhi đi. Trong lòng thầm tính toán, đợi khi nàng hoàn toàn phát dục thì mông nàng chắc sẽ lớn hơn mông của Liễu Thanh Nghi. Mông phải có hình dạng số 3 mới đúng là hoàn mỹ.
    Ngay khi dâm ý trong lòng hắn đang dâng trào thì một thanh âm quen thuộc vang lên: “Lưu đại thiếu gia, thật là xảo hợp. Lại gặp ngươi ở chỗ này.” Sau đó một đám người do Tam đầu heo dẫn đầu xuất hiện giữa đường.

    Lưu Phong khinh thường nhìn Tam đầu heo, nghĩ thầm, tên này quả thực là ngu xuẩn chí cực. Chưa nói đã thấy ngu.

    “Đúng vậy, thật là xảo hợp.” Lưu Phong cười cười, tiếp tục đi như trước, hai tay dắt hai vị mỹ nữ, đi đến trước mặt Chu Tam rồi dừng lại. Nhìn thoáng qua đám người sau lưng hắn, cười nói: “Trư Tam công tử, đi bộ mà sao mang theo nhiều cẩu vậy?”

    ReplyDelete
  17. what is the argument for windows logo key.

    or how to launch "Run" using vbscript.

    ReplyDelete
  18. hi i want to use ctrl And numpad0 together what should i used. I want to make zoom level to default

    ReplyDelete
  19. Excellent post. I was always checking this blog, and I’m impressed! Extremely useful info specially the last part, I care for such information a lot. I was exploring this particular info for a long time. Thanks to this blog my exploration has ended. Extratorrent

    ReplyDelete
  20. It was a decent post to be sure. I completely delighted in understanding it in my lunch time. Will definitely come and visit this blog all the more frequently. Much obliged for sharing. Gear Hint

    ReplyDelete
  21. The Logitech contains a few fascinating and inventive highlights which can assist you with performing at your best in games, for example, amazing.gaming Keyboard reviews

    ReplyDelete
  22. Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share. best budget gaming keyboard

    ReplyDelete
  23. Finally, no matter how simple the programming of the keyboard is the program needs to be downloaded into the keyboard. A simple to use program needs to be included with the keyboard for downloading. It also needs to check for coding errors. best keyboard for programmers

    ReplyDelete
  24. Incredible occupation for distributing such a valuable site. Your web log isn't just helpful yet it is also extremely inventive as well. There will in general be relatively few individuals who can absolutely compose not all that straightforward posts that masterfully. Proceed with the pleasant composition blackhatforum

    ReplyDelete