Automation Testing

ASCII CHR() CODE CHART for QTP UFT Selenium Playwright and Cypress

By Test Guild
  • Share:
Join the Guild for FREE

What is ASCII and Why it's Helpful to Know

ASCII stands for American Standard Code for Information Interchange, and it is a character encoding scheme based on the English alphabet.

Why does this matter?

For software development or automation of keyboard or mouse actions using automation tools like Unified functional testing or Selenium, this is very helpful.

For example, QuickTest Professional (QTP) and Unified Functional Testing (UFT) have two built-in functions (ASC and Chr) that are helpful to know when you need to work with ASCII info.

FYI this info here is not specific to QTP. Since ASCII is a standard any tool/language that you use would use the same Chr codes below. Also I originally posted this in 2010 but  the principles I cover are timeless)

Read on to learn more about:

  • The importance of knowing ASCII, including CHR(10) and other common codes
  • How to use these character codes 
  • How to send keyboard keys using Selenium, Playwright, and Cypress

Work With Me

Common ASCII Codes (The Most Used By QTP, And UFT Or Any Other Tool)

ASCII Laptop Image

Here are some of the most common QTP ASCII character codes I often use:

QTP CODE SYMBOL DESCRIPTION
Chr(34) Double Quotes
Chr(10) Line Feed
Chr(13) Carriage Return
Chr(32) Space

Chart for All the Valid Chr() Codes

QTP CODE SYMBOL DESCRIPTION
Chr(0) NUL Null char
Chr(1) SOH Start of Heading
Chr(2) STX Start of Text
Chr(3) ETX End of Text
Chr(4) EOT End of Transmission
Chr(5) ENQ Enquiry
Chr(6) ACK Acknowledgment
Chr(7) BEL Bell
Chr(8) BS Back Space
Chr(9) HT Horizontal Tab
Chr(10) LF Line Feed
Chr(11) VT Vertical Tab
Chr(12) FF Form Feed
Chr(13) CR Carriage Return
Chr(14) SO Shift Out / X-On
Chr(15) SI Shift In / X-Off
Chr(16) DLE Data Line Escape
Chr(17) DC1 Device Control 1 (oft. XON)
Chr(18) DC2 Device Control 2
Chr(19) DC3 Device Control 3 (oft. XOFF)
Chr(20) DC4 Device Control 4
Chr(21) NAK Negative Acknowledgement
Chr(22) SYN Synchronous Idle
Chr(23) ETB End of Transmit Block
Chr(24) CAN Cancel
Chr(25) EM End of Medium
Chr(26) SUB Substitute
Chr(27) ESC Escape
Chr(28) FS File Separator
Chr(29) GS Group Separator
Chr(30) RS Record Separator
Chr(31) US Unit Separator
Chr(32) Space
Chr(33) ! Exclamation mark
Chr(34) Double quotes (or speech marks)
Chr(35) # Number
Chr(36) $ Dollar
Chr(37) % Procenttecken
Chr(38) & Ampersand
Chr(39) Single quote
Chr(40) ( Open parenthesis (or open bracket)
Chr(41) ) Close parenthesis (or close bracket)
Chr(42) * Asterisk
Chr(43) + Plus
Chr(44) , Comma
Chr(45) Hyphen
Chr(46) . Period, dot or full stop
Chr(47) / Slash or divide
Chr(48) 0 Zero
Chr(49) 1 One
Chr(50) 2 Two
Chr(51) 3 Three
Chr(52) 4 Four
Chr(53) 5 Five
Chr(54) 6 Six
Chr(55) 7 Seven
Chr(56) 8 Eight
Chr(57) 9 Nine
Chr(58) : Colon
Chr(59) ; Semicolon
Chr(60) < Less than (or open angled bracket)
Chr(61) = Equals
Chr(62) > Greater than (or close angled bracket)
Chr(63) ? Question mark
Chr(64) @ At symbol
Chr(65) A Uppercase A
Chr(66) B Uppercase B
Chr(67) C Uppercase C
Chr(68) D Uppercase D
Chr(69) E Uppercase E
Chr(70) F Uppercase F
Chr(71) G Uppercase G
Chr(72) H Uppercase H
Chr(73) I Uppercase I
Chr(74) J Uppercase J
Chr(75) K Uppercase K
Chr(76) L Uppercase L
Chr(77) M Uppercase M
Chr(78) N Uppercase N
Chr(79) O Uppercase O
Chr(80) P Uppercase P
Chr(81) Q Uppercase Q
Chr(82) R Uppercase R
Chr(83) S Uppercase S
Chr(84) T Uppercase T
Chr(85) U Uppercase U
Chr(86) V Uppercase V
Chr(87) W Uppercase W
Chr(88) X Uppercase X
Chr(89) Y Uppercase Y
Chr(90) Z Uppercase Z
Chr(91) [ Opening bracket
Chr(92) \ Backslash
Chr(93) ] Closing bracket
Chr(94) ^ Caret – circumflex
Chr(95) _ Underscore
Chr(96) ` Grave accent
Chr(97) a Lowercase a
Chr(98) b Lowercase b
Chr(99) c Lowercase c
Chr(100) d Lowercase d
Chr(101) e Lowercase e
Chr(102) f Lowercase f
Chr(103) g Lowercase g
Chr(104) h Lowercase h
Chr(105) i Lowercase i
Chr(106) j Lowercase j
Chr(107) k Lowercase k
Chr(108) l Lowercase l
Chr(109) m Lowercase m
Chr(110) n Lowercase n
Chr(111) o Lowercase o
Chr(112) p Lowercase p
Chr(113) q Lowercase q
Chr(114) r Lowercase r
Chr(115) s Lowercase s
Chr(116) t Lowercase t
Chr(117) u Lowercase u
Chr(118) v Lowercase v
Chr(119) w Lowercase w
Chr(120) x Lowercase x
Chr(121) y Lowercase y
Chr(122) z Lowercase z
Chr(123) { Opening brace
Chr(124) | Vertical bar
Chr(125) } Closing brace
Chr(126) ~ Equivalency sign – tilde
Chr(127) Delete

 

Free TestGuild Courses

How can you actually use this?

ASC() Function

ASC()  is a QTP function that returns the code of the character passed to it. For example, if you wanted to know what the ASCII/ANSI code for the pound symbol #:

Msgbox Asc(“#”),

The above will return the code 35

Chr() Function

If you wanted to enter or search for the pound key in a string, you would use the QTP Chr() function. This function will return the character associated with the code passed to it. For example,

Msgbox Chr(35)

will return the pound sign.

That's not all…

What about mouse and keyboard actions in UFT or QTP?

There may be a time when you actually need to perform mouse or keyboard actions using screen coordinates. For a step-by-step example of how to do this with QuickTest Professional or Unified Functional Testing check out:

QTP Secret Code Chart Revealed For DeviceReplay PressKey, KeyDown, KeyUp and PressNKeys

Or

3 Ways to use keyboard input in QuickTest Professional or Unified Functional Testing

* Make sure to also check out  3 ways to use keyboard input in QuickTest Professional: Type, SendKeys and Device Replay for other ideas similar to using the  ASCII methods.

* Entering/Reading ASCII codes – when using Unified Functional Testing, previously known as Quick Test Professional (QTP) – is sometimes needed to achieve certain functionality. (For Selenium, check out Send_Keys)

Listen to Automation Testing Podcasts

What about Sending Keyboard Keys using Selenium?

If you're using Selenium for your test automation and you need to pass a keypress as you do in QTP, you're in luck.

Selenium has a send_keys command to send a keypress.

First, you need to import the org.openqa.selenium.Keys; library. Then, when you create your script, use the

.sendKeys(Keys.ENUM) syntax.

Here are some valid values you can pass:

ADD ALT ARROW_DOWN ARROW_LEFT ARROW_RIGHT ARROW_UP BACK_SPACE CANCEL
CLEAR COMMAND CONTROL DECIMAL DELETE DIVIDE
DOWN END ENTER EQUALS ESCAPE F1
F10 F11 F12 F2 F3 F4
F5 F6 F7 F8 F9 HELP
HOME INSERT LEFT LEFT_ALT LEFT_CONTROL LEFT_SHIFT
META MULTIPLY NULL NUMPAD0 NUMPAD1 NUMPAD2
NUMPAD3 NUMPAD4 NUMPAD5 NUMPAD6 NUMPAD7 NUMPAD8
NUMPAD9 PAGE_DOWN PAGE_UP PAUSE RETURN RIGHT
SEMICOLON SEPARATOR SHIFT SPACE SUBTRACT TAB and UP

* For more advanced actions check out the Advanced User Interactions post on SeleniumHQ

Send Keys using Playwright

Playwright's keyboard.press method simulates keyboard events in the browser. It takes a key as an argument and triggers a keydown, keypress, and keyup event in the browser. The key argument can be either a string or a key definition object.

Here is an example of how to use the keyboard.press method in Playwright to simulate pressing the ‘Enter' key:

await page.keyboard.press(‘Enter');

You can also simulate pressing multiple keys at once by passing an array of key definitions as the argument:

await page.keyboard.press([‘Shift', ‘KeyA']);

In addition to the keyboard.press method, Playwright's keyboard API also provides other methods such as keyboard.down, keyboard.up, and keyboard.type to simulate other keyboard events.

Here's an example of how to use keyboard.type to simulate typing a string of text:

await page.keyboard.type(‘Hello, World!');

This will simulate pressing each key on the keyboard in sequence to type out the text “Hello, World!” in the active input field.

Overall, the keyboard API in Playwright is powerful and flexible, allowing you to simulate a wide range of keyboard events and interactions in the browser.

Here is the full table of ASCII codes and how to use them with Playwright:

Character ASCII Code Playwright Syntax
null 0 await page.keyboard.press('Null');
SOH 1 await page.keyboard.press('1');
STX 2 await page.keyboard.press('2');
ETX 3 await page.keyboard.press('3');
EOT 4 await page.keyboard.press('4');
ENQ 5 await page.keyboard.press('5');
ACK 6 await page.keyboard.press('6');
BEL 7 await page.keyboard.press('7');
BS 8 await page.keyboard.press('Backspace');
TAB 9 await page.keyboard.press('Tab');
LF 10 await page.keyboard.press('Enter');
VT 11 await page.keyboard.press('11');
FF 12 await page.keyboard.press('12');
CR 13 await page.keyboard.press('13');
SO 14 await page.keyboard.press('14');
SI 15 await page.keyboard.press('15');
DLE 16 await page.keyboard.press('16');
DC1 17 await page.keyboard.press('17');
DC2 18 await page.keyboard.press('18');
DC3 19 await page.keyboard.press('19');
DC4 20 await page.keyboard.press('20');
NAK 21 await page.keyboard.press('21');
SYN 22 await page.keyboard.press('22');
ETB 23 await page.keyboard.press('23');
CAN 24 await page.keyboard.press('24');
EM 25 await page.keyboard.press('25');
SUB 26 await page.keyboard.press('26');
ESC 27 await page.keyboard.press('Escape');
FS 28 await page.keyboard.press('28');
GS 29 await page.keyboard.press('29');
RS 30 await page.keyboard.press('30');
US 31 await page.keyboard.press('31');
space 32 await page.keyboard.press('Space');
! 33 await page.keyboard.press('!');
34 await page.keyboard.press('"');
# 35 `await page

Send Keys using Cypress

The cy.type() command in Cypress is used to simulate typing input into a form field or any other input element on a web page. It allows you to input text, numbers, special characters, and control keys like enter, tab, and backspace.

The syntax for cy.type() command is:

cy.get(‘selector').type(text, options)

Here, selector is the selector for the element that you want to type into, text is the text that you want to input, and options is an optional object that you can use to specify various typing options like delay, modifiers, and special keys.

For example, to type the text “Hello, World!” into an input field, you can use the following code:

cy.get(‘#my-input-field').type(‘Hello, World!');

You can also use the cy.type() command to simulate typing special keys and control keys like enter, tab, and backspace by passing them in curly braces as shown in the ASCII codes table earlier.

Here is an example of typing the ‘Enter' key using the cy.type() command:

cy.get(‘#my-input-field').type(‘{enter}');

In addition, you can also use the cy.type() command to simulate typing with modifiers like ‘ctrl' or ‘shift' by passing them as an option in the options object.

For example, to simulate typing the ‘A' key with the ‘ctrl' key pressed down, you can use the following code:

cy.get(‘#my-input-field').type(‘a', { ctrlKey: true });

Overall, the cy.type() command is a versatile and powerful command in Cypress that allows you to simulate various types of input interactions in your tests.

Here is a table of additional ASCII codes and how to use them with Cypress:

Character ASCII Code Cypress Syntax
null 0 cy.type('{NULL}');
SOH 1 cy.type('{SOH}');
STX 2 cy.type('{STX}');
ETX 3 cy.type('{ETX}');
EOT 4 cy.type('{EOT}');
ENQ 5 cy.type('{ENQ}');
ACK 6 cy.type('{ACK}');
BEL 7 cy.type('{BEL}');
BS 8 cy.type('{backspace}');
TAB 9 cy.type('{tab}');
LF 10 cy.type('{enter}');
VT 11 cy.type('{VT}');
FF 12 cy.type('{FF}');
CR 13 cy.type('{enter}');
SO 14 cy.type('{SO}');
SI 15 cy.type('{SI}');
DLE 16 cy.type('{DLE}');
DC1 17 cy.type('{DC1}');
DC2 18 cy.type('{DC2}');
DC3 19 cy.type('{DC3}');
DC4 20 cy.type('{DC4}');
NAK 21 cy.type('{NAK}');
SYN 22 cy.type('{SYN}');
ETB 23 cy.type('{ETB}');
CAN 24 cy.type('{CAN}');
EM 25 cy.type('{EM}');
SUB 26 cy.type('{SUB}');
ESC 27 cy.type('{esc}');
FS 28 cy.type('{FS}');
GS 29 cy.type('{GS}');
RS 30 cy.type('{RS}');
US 31 cy.type('{US}');
space 32 cy.type(' ');
! 33 cy.type('!');
34 cy.type('"');
# 35 cy.type('#');
$ 36 cy.type('$');
% 37 cy.type('%');

 

  1. I am having a heck of a time trying to figure out why my customer says they cannot see the RS/ chr(30) in this string. I am using vb script for a barcode. Can you tell why?

    “[)>”&Chr(30)&”06″&Chr(29)&”1P”&Field(“psr120.1_part_no”)&Chr(29)&”Q”&Field(“psr120.6_act_wgt”)&Chr(29)& “K”&Field(“psr120.4_cust_order”)&Field(“psr120.cust_po_release”)&Chr(29)&”1T”&Field(“psr120.mat_cert_num”)& Chr(29)&”3S”&Field(“psr120.tag”)& Chr(30)&Chr(04)

    TIA

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

DevAssure Review: Cut Testing Time Using Low Code Automation?

Posted on 12/11/2024

As you know, testing often becomes a bottleneck in software development due to ...

Leveraging AI and Playwright for Test Case Generation

Posted on 11/22/2024

Two BIG trends the past few years in the software testing space been ...

Symbolic AI vs. Gen AI: The Dynamic Duo in Test Automation

Posted on 09/23/2024

You've probably been having conversations lately about whether to use AI for testing. ...

Automation Guild '25 Online Event - Registration Kickoff Special (Limited Time) - Elevate your E2E testing skills in 2025 >>