Robot Framework using Python, Key Press without selecting any button or element in the page
I am automating one application using robot framework using Python. In a certain situation I need to press enter without selecting any button or element of the page once the page is loaded.
I have tried with the below example but it didn't work as I don't want to select any specific button or element of the page before press enter on the page.
Examples:
Press Key text_field q
Press Key login_button \13 # ASCII code for enter key
Below Keyword is not recognized by the IDE, most probably because of version:
Press Key Native
So can anyone give me a solution to get rid of this problem ?
Thanks in advance :)
python-2.7 keypress robotframework
add a comment |
I am automating one application using robot framework using Python. In a certain situation I need to press enter without selecting any button or element of the page once the page is loaded.
I have tried with the below example but it didn't work as I don't want to select any specific button or element of the page before press enter on the page.
Examples:
Press Key text_field q
Press Key login_button \13 # ASCII code for enter key
Below Keyword is not recognized by the IDE, most probably because of version:
Press Key Native
So can anyone give me a solution to get rid of this problem ?
Thanks in advance :)
python-2.7 keypress robotframework
Have you tried using the document root as the target of the "Press Key"?
– Bryan Oakley
Jul 28 '15 at 19:08
add a comment |
I am automating one application using robot framework using Python. In a certain situation I need to press enter without selecting any button or element of the page once the page is loaded.
I have tried with the below example but it didn't work as I don't want to select any specific button or element of the page before press enter on the page.
Examples:
Press Key text_field q
Press Key login_button \13 # ASCII code for enter key
Below Keyword is not recognized by the IDE, most probably because of version:
Press Key Native
So can anyone give me a solution to get rid of this problem ?
Thanks in advance :)
python-2.7 keypress robotframework
I am automating one application using robot framework using Python. In a certain situation I need to press enter without selecting any button or element of the page once the page is loaded.
I have tried with the below example but it didn't work as I don't want to select any specific button or element of the page before press enter on the page.
Examples:
Press Key text_field q
Press Key login_button \13 # ASCII code for enter key
Below Keyword is not recognized by the IDE, most probably because of version:
Press Key Native
So can anyone give me a solution to get rid of this problem ?
Thanks in advance :)
python-2.7 keypress robotframework
python-2.7 keypress robotframework
edited Jul 28 '15 at 17:53
Andy Mikhaylenko
80789
80789
asked Feb 24 '15 at 4:28


Arunava DasguptaArunava Dasgupta
26113
26113
Have you tried using the document root as the target of the "Press Key"?
– Bryan Oakley
Jul 28 '15 at 19:08
add a comment |
Have you tried using the document root as the target of the "Press Key"?
– Bryan Oakley
Jul 28 '15 at 19:08
Have you tried using the document root as the target of the "Press Key"?
– Bryan Oakley
Jul 28 '15 at 19:08
Have you tried using the document root as the target of the "Press Key"?
– Bryan Oakley
Jul 28 '15 at 19:08
add a comment |
4 Answers
4
active
oldest
votes
Robot Framework Selenium library can only send keypresses to an element. If you want to send actual keypresses, you need to write your own library that does it. In Windows this can be done using SendKeys module.
Here is a library that defines "Send Enter Key" keyword for Robot Framework. I tested it quickly on Chrome, it might have problems with PhantomJS.
import SendKeys
def send_enter_key():
"""
Sends ENTER key to application
Works only in Windows
"""
SendKeys.SendKeys("{ENTER}")
1
Is there linux alternative?
– user2988257
Aug 30 '16 at 8:54
add a comment |
Try it with two slashes not three
Press Key text_field q
Press Key login_button 13 # ASCII code for enter key
If you inject it as a variable, it is one slash. If you use it directly, it is two.
– angryip
Dec 13 '17 at 14:20
add a comment |
Linux Alternative can be PyAutoGUI
Although it works for Windows and MacOS(cross-platform) also, as described in the docs
PyAutoGUI works on Python 2 & 3. Install from PyPI with
pip install pyautogui
Examples:
import pyautogui
def send_keys():
"""
Works on Windows/Mac/Linux
"""
pyautogui.press('enter') #Presses enter
pyautogui.hotkey('ctrl', 'shift', 'esc') #Performs ctrl+shift+esc
pyautogui.typewrite('Hello world!n', interval=secs_between_keys) #Useful for entering text, newline is Enter
pyautogui.typewrite(['a', 'b', 'c', 'left', 'backspace', 'enter', 'f1'], interval=.4) #A list of key names can be passed too
add a comment |
If you want to send a key press event to the page, but not at a specific element - target the <body>
element in the page, using the Press Key
keyword:
Press Key xpath=//body ue00f # this is the Page Down key
Press Key css=body ue00e # and this - Page Up
An up-to-date list of key codes can be found in selenium's source, the webdriver.common.Keys module holds their definition.
IMHO libraries that execute keystrokes in the OS (like AutoIt, or Java's robot) should be avoided if possible - they make your automation scrip[ts dependent on the execution machine (and operating system), local only, and naturally you can't run browsers tests against Selenium Hub (Sauce labs, Browsertstack, similar).
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28688170%2frobot-framework-using-python-key-press-without-selecting-any-button-or-element%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Robot Framework Selenium library can only send keypresses to an element. If you want to send actual keypresses, you need to write your own library that does it. In Windows this can be done using SendKeys module.
Here is a library that defines "Send Enter Key" keyword for Robot Framework. I tested it quickly on Chrome, it might have problems with PhantomJS.
import SendKeys
def send_enter_key():
"""
Sends ENTER key to application
Works only in Windows
"""
SendKeys.SendKeys("{ENTER}")
1
Is there linux alternative?
– user2988257
Aug 30 '16 at 8:54
add a comment |
Robot Framework Selenium library can only send keypresses to an element. If you want to send actual keypresses, you need to write your own library that does it. In Windows this can be done using SendKeys module.
Here is a library that defines "Send Enter Key" keyword for Robot Framework. I tested it quickly on Chrome, it might have problems with PhantomJS.
import SendKeys
def send_enter_key():
"""
Sends ENTER key to application
Works only in Windows
"""
SendKeys.SendKeys("{ENTER}")
1
Is there linux alternative?
– user2988257
Aug 30 '16 at 8:54
add a comment |
Robot Framework Selenium library can only send keypresses to an element. If you want to send actual keypresses, you need to write your own library that does it. In Windows this can be done using SendKeys module.
Here is a library that defines "Send Enter Key" keyword for Robot Framework. I tested it quickly on Chrome, it might have problems with PhantomJS.
import SendKeys
def send_enter_key():
"""
Sends ENTER key to application
Works only in Windows
"""
SendKeys.SendKeys("{ENTER}")
Robot Framework Selenium library can only send keypresses to an element. If you want to send actual keypresses, you need to write your own library that does it. In Windows this can be done using SendKeys module.
Here is a library that defines "Send Enter Key" keyword for Robot Framework. I tested it quickly on Chrome, it might have problems with PhantomJS.
import SendKeys
def send_enter_key():
"""
Sends ENTER key to application
Works only in Windows
"""
SendKeys.SendKeys("{ENTER}")
answered Mar 11 '15 at 7:45
PekkaPekka
1,249811
1,249811
1
Is there linux alternative?
– user2988257
Aug 30 '16 at 8:54
add a comment |
1
Is there linux alternative?
– user2988257
Aug 30 '16 at 8:54
1
1
Is there linux alternative?
– user2988257
Aug 30 '16 at 8:54
Is there linux alternative?
– user2988257
Aug 30 '16 at 8:54
add a comment |
Try it with two slashes not three
Press Key text_field q
Press Key login_button 13 # ASCII code for enter key
If you inject it as a variable, it is one slash. If you use it directly, it is two.
– angryip
Dec 13 '17 at 14:20
add a comment |
Try it with two slashes not three
Press Key text_field q
Press Key login_button 13 # ASCII code for enter key
If you inject it as a variable, it is one slash. If you use it directly, it is two.
– angryip
Dec 13 '17 at 14:20
add a comment |
Try it with two slashes not three
Press Key text_field q
Press Key login_button 13 # ASCII code for enter key
Try it with two slashes not three
Press Key text_field q
Press Key login_button 13 # ASCII code for enter key
answered Jun 29 '17 at 7:22
user8230233user8230233
111
111
If you inject it as a variable, it is one slash. If you use it directly, it is two.
– angryip
Dec 13 '17 at 14:20
add a comment |
If you inject it as a variable, it is one slash. If you use it directly, it is two.
– angryip
Dec 13 '17 at 14:20
If you inject it as a variable, it is one slash. If you use it directly, it is two.
– angryip
Dec 13 '17 at 14:20
If you inject it as a variable, it is one slash. If you use it directly, it is two.
– angryip
Dec 13 '17 at 14:20
add a comment |
Linux Alternative can be PyAutoGUI
Although it works for Windows and MacOS(cross-platform) also, as described in the docs
PyAutoGUI works on Python 2 & 3. Install from PyPI with
pip install pyautogui
Examples:
import pyautogui
def send_keys():
"""
Works on Windows/Mac/Linux
"""
pyautogui.press('enter') #Presses enter
pyautogui.hotkey('ctrl', 'shift', 'esc') #Performs ctrl+shift+esc
pyautogui.typewrite('Hello world!n', interval=secs_between_keys) #Useful for entering text, newline is Enter
pyautogui.typewrite(['a', 'b', 'c', 'left', 'backspace', 'enter', 'f1'], interval=.4) #A list of key names can be passed too
add a comment |
Linux Alternative can be PyAutoGUI
Although it works for Windows and MacOS(cross-platform) also, as described in the docs
PyAutoGUI works on Python 2 & 3. Install from PyPI with
pip install pyautogui
Examples:
import pyautogui
def send_keys():
"""
Works on Windows/Mac/Linux
"""
pyautogui.press('enter') #Presses enter
pyautogui.hotkey('ctrl', 'shift', 'esc') #Performs ctrl+shift+esc
pyautogui.typewrite('Hello world!n', interval=secs_between_keys) #Useful for entering text, newline is Enter
pyautogui.typewrite(['a', 'b', 'c', 'left', 'backspace', 'enter', 'f1'], interval=.4) #A list of key names can be passed too
add a comment |
Linux Alternative can be PyAutoGUI
Although it works for Windows and MacOS(cross-platform) also, as described in the docs
PyAutoGUI works on Python 2 & 3. Install from PyPI with
pip install pyautogui
Examples:
import pyautogui
def send_keys():
"""
Works on Windows/Mac/Linux
"""
pyautogui.press('enter') #Presses enter
pyautogui.hotkey('ctrl', 'shift', 'esc') #Performs ctrl+shift+esc
pyautogui.typewrite('Hello world!n', interval=secs_between_keys) #Useful for entering text, newline is Enter
pyautogui.typewrite(['a', 'b', 'c', 'left', 'backspace', 'enter', 'f1'], interval=.4) #A list of key names can be passed too
Linux Alternative can be PyAutoGUI
Although it works for Windows and MacOS(cross-platform) also, as described in the docs
PyAutoGUI works on Python 2 & 3. Install from PyPI with
pip install pyautogui
Examples:
import pyautogui
def send_keys():
"""
Works on Windows/Mac/Linux
"""
pyautogui.press('enter') #Presses enter
pyautogui.hotkey('ctrl', 'shift', 'esc') #Performs ctrl+shift+esc
pyautogui.typewrite('Hello world!n', interval=secs_between_keys) #Useful for entering text, newline is Enter
pyautogui.typewrite(['a', 'b', 'c', 'left', 'backspace', 'enter', 'f1'], interval=.4) #A list of key names can be passed too
edited Aug 9 '18 at 9:52
answered Aug 9 '18 at 9:37


Aneez AhmedAneez Ahmed
235
235
add a comment |
add a comment |
If you want to send a key press event to the page, but not at a specific element - target the <body>
element in the page, using the Press Key
keyword:
Press Key xpath=//body ue00f # this is the Page Down key
Press Key css=body ue00e # and this - Page Up
An up-to-date list of key codes can be found in selenium's source, the webdriver.common.Keys module holds their definition.
IMHO libraries that execute keystrokes in the OS (like AutoIt, or Java's robot) should be avoided if possible - they make your automation scrip[ts dependent on the execution machine (and operating system), local only, and naturally you can't run browsers tests against Selenium Hub (Sauce labs, Browsertstack, similar).
add a comment |
If you want to send a key press event to the page, but not at a specific element - target the <body>
element in the page, using the Press Key
keyword:
Press Key xpath=//body ue00f # this is the Page Down key
Press Key css=body ue00e # and this - Page Up
An up-to-date list of key codes can be found in selenium's source, the webdriver.common.Keys module holds their definition.
IMHO libraries that execute keystrokes in the OS (like AutoIt, or Java's robot) should be avoided if possible - they make your automation scrip[ts dependent on the execution machine (and operating system), local only, and naturally you can't run browsers tests against Selenium Hub (Sauce labs, Browsertstack, similar).
add a comment |
If you want to send a key press event to the page, but not at a specific element - target the <body>
element in the page, using the Press Key
keyword:
Press Key xpath=//body ue00f # this is the Page Down key
Press Key css=body ue00e # and this - Page Up
An up-to-date list of key codes can be found in selenium's source, the webdriver.common.Keys module holds their definition.
IMHO libraries that execute keystrokes in the OS (like AutoIt, or Java's robot) should be avoided if possible - they make your automation scrip[ts dependent on the execution machine (and operating system), local only, and naturally you can't run browsers tests against Selenium Hub (Sauce labs, Browsertstack, similar).
If you want to send a key press event to the page, but not at a specific element - target the <body>
element in the page, using the Press Key
keyword:
Press Key xpath=//body ue00f # this is the Page Down key
Press Key css=body ue00e # and this - Page Up
An up-to-date list of key codes can be found in selenium's source, the webdriver.common.Keys module holds their definition.
IMHO libraries that execute keystrokes in the OS (like AutoIt, or Java's robot) should be avoided if possible - they make your automation scrip[ts dependent on the execution machine (and operating system), local only, and naturally you can't run browsers tests against Selenium Hub (Sauce labs, Browsertstack, similar).
answered Jan 14 at 18:53


Todor MinakovTodor Minakov
6,24112136
6,24112136
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28688170%2frobot-framework-using-python-key-press-without-selecting-any-button-or-element%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you tried using the document root as the target of the "Press Key"?
– Bryan Oakley
Jul 28 '15 at 19:08