Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work key simulation ( send_keys ) #160

Open
LarryDi opened this issue Mar 30, 2017 · 8 comments
Open

Doesn't work key simulation ( send_keys ) #160

LarryDi opened this issue Mar 30, 2017 · 8 comments

Comments

@LarryDi
Copy link

LarryDi commented Mar 30, 2017

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?

@heilwood
Copy link

for me also not working, i'm using windows.forms.sendkeys class in c# for key combos.

@heilwood
Copy link

heilwood commented Jul 6, 2017

if you would like to send Enter using actions or any other button you need to add to dictionary Modifiers and ModifiersMap keys which you want to use in class KeyboardModifiers. Then you can use
actions = ActionChains(driver) actions.send_keys(Keys.Enter).send_keys('some_Text').send_keys(Keys.Enter)

@Ahsanmumtaz1105
Copy link

add to dictionary Modifiers and ModifiersMap keys which you want to use in class KeyboardModifiers ? What library I want to import to simulate keyboard keys i.e. ENTER, BACKSPACE.?

@heilwood
Copy link

If you would like to have this in winium you should download source code of the project, add required keys to dictionary ModifiersMap which is in class Modifiers.cs, then compile the project.

@SanjeevKumarmn
Copy link

It doesn't work for me too,I tried actions and sendkeys. I ended up using awt robot and it works.

@voloxastik
Copy link

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

internal class KeyboardModifiers : List
{
#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 },
            };

@shivalkar
Copy link

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
{
#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 },
            };

@gmehta1996
Copy link

How do we put letters in this. For ex. if I want to press Control + H through ActionChains.How to add letters in the modifier file.
Thank You

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants