Winium.Desktop
Winium.Desktop copied to clipboard
Doesn't work key simulation ( send_keys )
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?
for me also not working, i'm using windows.forms.sendkeys class in c# for key combos.
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)
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.?
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.
It doesn't work for me too,I tried actions and sendkeys. I ended up using awt robot and it works.
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 },
};
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
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 },
};
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