question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't work key simulation ( send_keys )

See original GitHub issue

Winium.Desktop v.1.6.0 Selenium v.3.0.2 Python v.3.4.4

Using examples from Wiki and habrahabr article:

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
import time

driver = webdriver.Remote(
    command_executor='http://localhost:9999',
    desired_capabilities={
        "debugConnectToRunningApp": 'false',
        "app": r"C:/windows/system32/notepad.exe"
    })

time.sleep(0.5)
window = driver.find_element_by_class_name('Notepad')
text_field = window.find_element_by_class_name('Edit')

text_field.click()
text_field.send_keys('Some text{ENTER}{ENTER}')

actions = ActionChains(driver)
actions.send_keys('Another text{ENTER}')
actions.send_keys('^{o}')
actions.perform()

ActionChains(driver).key_down(Keys.CONTROL).send_keys('o').key_up(Keys.CONTROL).perform()
ActionChains(driver).key_down('\ue009').send_keys('o').key_up('\ue009').perform()

Result: “Some text{ENTER}{ENTER}Another text{ENTER}^{o}oo” Keys simulation does not work.

Is it bug or i do something wrong? If the second, what exactly wrong?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
shivalkarcommented, Aug 14, 2019

By updating below code in KeyboardModifiers.cs class, will allow you to use Enter key Winium.Desktop.Driver\Input\KeyboardModifiers.cs internal class KeyboardModifiers : List<string> { #region Static Fields

    private static readonly List<string> Modifiers = new List<string>
                                                         {
                                                            Keys.Control,
                                                            Keys.LeftControl,
                                                            Keys.Shift,
                                                            Keys.LeftShift,
                                                            Keys.Alt,
                                                            Keys.ArrowDown,
                                                            Keys.ArrowUp,
                                                            Keys.PageDown,
                                                            Keys.PageUp,
                                                            Keys.LeftAlt,
                                                            Keys.Enter,
                                                            Keys.Tab,
                                                            Keys.Clear,
                                                            Keys.Delete,
                                                            Keys.Backspace
                                                         };

    private static readonly Dictionary<string, VirtualKeyCode> ModifiersMap =
        new Dictionary<string, VirtualKeyCode>
            {
                { Keys.Control, VirtualKeyCode.CONTROL },
                { Keys.Shift, VirtualKeyCode.SHIFT },
                { Keys.Alt, VirtualKeyCode.MENU },
                { Keys.ArrowUp, VirtualKeyCode.UP },
                { Keys.ArrowDown, VirtualKeyCode.DOWN },
                { Keys.PageUp, VirtualKeyCode.PRIOR },
                { Keys.PageDown, VirtualKeyCode.NEXT },
                { Keys.Enter, VirtualKeyCode.RETURN },
                { Keys.Tab, VirtualKeyCode.TAB },
                { Keys.Clear, VirtualKeyCode.CLEAR },
                { Keys.Delete, VirtualKeyCode.DELETE },
                { Keys.Backspace, VirtualKeyCode.BACK },
            };
1reaction
voloxastikcommented, Feb 28, 2018

Winium.Desktop.Driver\Winium.Desktop-1.6.0\src\Winium.Desktop.Driver\Input\KeyboardModifiers.cs

internal class KeyboardModifiers : List<string> { #region Static Fields

    private static readonly List<string> Modifiers = new List<string>
                                                         {
                                                             Keys.Control, 
                                                             Keys.LeftControl, 
                                                             Keys.Shift, 
                                                             Keys.LeftShift, 
                                                             Keys.Alt, 
                                                             Keys.ArrowDown,
                                                             Keys.ArrowUp,
                                                             Keys.PageDown,
                                                             Keys.PageUp,
                                                             Keys.LeftAlt
                                                         };

    private static readonly Dictionary<string, VirtualKeyCode> ModifiersMap =
        new Dictionary<string, VirtualKeyCode>
            {
                { Keys.Control, VirtualKeyCode.CONTROL },
                { Keys.Shift, VirtualKeyCode.SHIFT },
                { Keys.Alt, VirtualKeyCode.MENU },
                { Keys.ArrowUp, VirtualKeyCode.UP },
                { Keys.ArrowDown, VirtualKeyCode.DOWN },
                { Keys.PageUp, VirtualKeyCode.PRIOR },
                { Keys.PageDown, VirtualKeyCode.NEXT },
            };
Read more comments on GitHub >

github_iconTop Results From Across the Web

send_keys() method doesn't work for entering Passcode on ...
1 Answer 1 ... Can you try to click or tap, the individual elements(numbers) instead of using sendKeys, usually you use sendKeys for...
Read more >
[Solved] Keyboard simulation does not work for game
Hi I simulated keyboard using c#,this code work fine and send command to IE, Notepad, Crome,but it fail to send command to game...
Read more >
How to Use Excel SendKeys Method in Macros
You can use the SendKeys method in your Excel macros VBA code, to simulate keystrokes that you would manually input in the active...
Read more >
Selenium SendKeys: A Detailed Usage Guide With Examples
SendKeys is a method used to send keyboard input such as characters ... In such cases, just finding the element and sending keys...
Read more >
Selenium SendKeys: A Detailed Usage Guide
Selenium Sendkeys is a method used in Selenium WebDriver to simulate the typing of a keyboard key in a web application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found