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

Element SendKeys does not send keydown/keyup events for shift key when sending "shifted" keystrokes #646

Open
2 tasks done
jimevans opened this issue Apr 12, 2017 · 11 comments

Comments

@jimevans
Copy link

In order to help us efficiently investigate your issue, please provide the following information:

Firefox Version

55.0a1 (2017-04-12) (32-bit)
geckodriver as of commit 15345b6

Platform

Windows

Steps to reproduce

Execute the following code using the Selenium .NET bindings (exact W3C WebDriver protocol commands are included as comments):

FirefoxOptions options = new FirefoxOptions();
options.LogLevel = FirefoxDriverLogLevel.Trace;
options.BrowserExecutableLocation = @"C:\Program Files (x86)\Nightly\firefox.exe";

// POST /session
// command body:
// {
//     "capabilities": {
//         "alwaysMatch" : {
//             "browserName": "firefox",
//             "acceptInsecureCerts": true,
//             "moz:firefoxOptions": {
//                 "binary": "C:\Program Files (x86)\Nightly\firefox.exe",
//                 "log": {
//                     "level": "trace"
//                 }
//             }
//         }
//    }
// }
IWebDriver driver = new FirefoxDriver(options);

// POST /session/{sessionId}/url
// Request Body: { "url": "<url to the hosted HTML file, provided below>" }
driver.Url = "<url to HTML file, provided below>";

// POST /session/{sessionId}/element
// Request Body: { "using": "css selector", "value": "#result" }
IWebElement result = driver.FindElement(By.CssSelector("#result"));

// POST /session/{sessionId}/element
// Request Body: { "using": "css selector", "value": "#result" }
IWebElement element = driver.FindElement(By.CssSelector("#keyReporter"));

// POST /session/{sessionId}/element/{elementId}/value
// Request Body: { "text": "~" }
element.SendKeys("~");

// GET /session/{sessionId}/element/{elementId}/text
string text = result.Text.Trim();

Expect: The result element to include a record of the keyUp event for the shift key.

Result: The shift key is not represented in the key events propagated to the element.

  • A minimal HTML file (or files) that can be used to reproduce the issue
<!DOCTYPE html>
<html>
<head>
    <title>Testing Keyboard Events</title>
    <script type="text/javascript">
        function displayMessage(message) {
            document.getElementById('resultParagraph').innerHTML = message;
        }

        function appendMessage(message) {
            document.getElementById('resultParagraph').innerHTML += message + " ";
        }
    </script>
</head>
<body>
<div id="resultContainer" height="30">&nbsp;
  <div id="result" style="width:300;height:60">
    <p id="resultParagraph">&nbsp;</p>
  </div>

</div>
                                                                                         

<div>
    <form>
        <input type="text" id="keyReporter" size="80"
               onkeyup="appendMessage('up: ' + event.keyCode)"
               onkeypress="appendMessage('press: ' + event.keyCode)"
               onkeydown="displayMessage(''); appendMessage('down: ' + event.keyCode)" />
    </form>
</div>

</body>
</html>
  • A trace level log from a geckodriver session that demonstrates the problem using the minimal example file.
1492039243905   geckodriver     INFO    Listening on 127.0.0.1:57640
1492039245178   geckodriver::marionette INFO    Starting browser \\?\C:\Program Files (x86)\Nightly\firefox.exe with args ["-marionette"]
1492039247447   geckodriver::marionette DEBUG   Connected to Marionette on localhost:57666
1492039247471   geckodriver::marionette TRACE   ← {"applicationType":"gecko","marionetteProtocol":3}
1492039247496   geckodriver::marionette TRACE   → 269:[0,1,"newSession",{"acceptInsecureCerts":true,"browserName":"firefox","capabilities":{"desiredCapabilities":{"acceptInsecureCerts":true,"browserName":"firefox","platform":"ANY","specificationLevel":1,"version":""}},"platform":"ANY","specificationLevel":1,"version":""}]
1492039248263   geckodriver::marionette TRACE   ← [1,1,null,{"sessionId":"4f3d9847-2fcc-41d9-b176-25a294e4ab09","capabilities":{"browserName":"firefox","browserVersion":"55.0a1","platformName":"windows_nt","platformVersion":"10.0","pageLoadStrategy":"normal","acceptInsecureCerts":true,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"rotatable":false,"specificationLevel":1,"moz:processID":20156,"moz:profile":"C:\\Users\\seatt\\AppData\\Local\\Temp\\rust_mozprofile.BQTZ7ZDiAoIp","moz:accessibilityChecks":false}}]
1492039248279   webdriver::server       DEBUG   Returning status Ok
1492039248338   webdriver::server       DEBUG   Returning body {"value": {"sessionId":"4f3d9847-2fcc-41d9-b176-25a294e4ab09","capabilities":{"acceptInsecureCerts":true,"browserName":"firefox","browserVersion":"55.0a1","moz:accessibilityChecks":false,"moz:processID":20156,"moz:profile":"C:\\Users\\seatt\\AppData\\Local\\Temp\\rust_mozprofile.BQTZ7ZDiAoIp","pageLoadStrategy":"normal","platformName":"windows_nt","platformVersion":"10.0","rotatable":false,"specificationLevel":1,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000}}}}
1492039248383   webdriver::server       DEBUG   Got request POST AbsolutePath("/session/4f3d9847-2fcc-41d9-b176-25a294e4ab09/url")
1492039248386   webdriver::command      DEBUG   Got request body {"url":"http://localhost:2310/common/keyboardPage.html"}
1492039248387   geckodriver::marionette TRACE   → 68:[0,2,"get",{"url":"http://localhost:2310/common/keyboardPage.html"}]
1492039248489   geckodriver::marionette TRACE   ← [1,2,null,{}]
1492039248500   webdriver::server       DEBUG   Returning status Ok
1492039248500   webdriver::server       DEBUG   Returning body {"value": {}}
1492039248505   webdriver::server       DEBUG   Got request POST AbsolutePath("/session/4f3d9847-2fcc-41d9-b176-25a294e4ab09/element")
1492039248506   webdriver::command      DEBUG   Got request body {"using":"css selector","value":"#result"}
1492039248507   geckodriver::marionette TRACE   → 62:[0,3,"findElement",{"using":"css selector","value":"#result"}]
1492039248516   geckodriver::marionette TRACE   ← [1,3,null,{"value":{"element-6066-11e4-a52e-4f735466cecf":"fb4ba561-adc0-4518-ae20-d1afe6566fa7","ELEMENT":"fb4ba561-adc0-4518-ae20-d1afe6566fa7"}}]
1492039248517   webdriver::server       DEBUG   Returning status Ok
1492039248517   webdriver::server       DEBUG   Returning body {"value":{"element-6066-11e4-a52e-4f735466cecf":"fb4ba561-adc0-4518-ae20-d1afe6566fa7"}}
1492039248519   webdriver::server       DEBUG   Got request POST AbsolutePath("/session/4f3d9847-2fcc-41d9-b176-25a294e4ab09/element")
1492039248520   webdriver::command      DEBUG   Got request body {"using":"css selector","value":"#keyReporter"}
1492039248520   geckodriver::marionette TRACE   → 67:[0,4,"findElement",{"using":"css selector","value":"#keyReporter"}]
1492039248526   geckodriver::marionette TRACE   ← [1,4,null,{"value":{"element-6066-11e4-a52e-4f735466cecf":"3d17ca03-89c3-456d-be6a-5c42140167da","ELEMENT":"3d17ca03-89c3-456d-be6a-5c42140167da"}}]
1492039248527   webdriver::server       DEBUG   Returning status Ok
1492039248527   webdriver::server       DEBUG   Returning body {"value":{"element-6066-11e4-a52e-4f735466cecf":"3d17ca03-89c3-456d-be6a-5c42140167da"}}
1492039248534   webdriver::server       DEBUG   Got request POST AbsolutePath("/session/4f3d9847-2fcc-41d9-b176-25a294e4ab09/element/3d17ca03-89c3-456d-be6a-5c42140167da/value")
1492039248535   webdriver::command      DEBUG   Got request body {"text":"~","value":["~"]}
1492039248535   geckodriver::marionette TRACE   → 96:[0,5,"sendKeysToElement",{"id":"3d17ca03-89c3-456d-be6a-5c42140167da","text":"~","value":["~"]}]
1492039248628   geckodriver::marionette TRACE   ← [1,5,null,{}]
1492039248665   webdriver::server       DEBUG   Returning status Ok
1492039248665   webdriver::server       DEBUG   Returning body {"value": {}}
1492039248666   webdriver::server       DEBUG   Got request GET AbsolutePath("/session/4f3d9847-2fcc-41d9-b176-25a294e4ab09/element/fb4ba561-adc0-4518-ae20-d1afe6566fa7/text")
1492039248667   geckodriver::marionette TRACE   → 68:[0,6,"getElementText",{"id":"fb4ba561-adc0-4518-ae20-d1afe6566fa7"}]
1492039248681   geckodriver::marionette TRACE   ← [1,6,null,{"value":"down: 192 press: 0 up: 192"}]
1492039248684   webdriver::server       DEBUG   Returning status Ok
1492039248687   webdriver::server       DEBUG   Returning body {"value":"down: 192 press: 0 up: 192"}
@andreastt
Copy link
Contributor

Maybe this is indirectly related to a #645, in that they both rely on testing/marionette/event.js for synthesizing interaction and DOM events. We could either not be picking up the right “magic Unicode character” for the shifted state, or we are failing to set the shifted modifier state when we call event.js.

@altus34
Copy link

altus34 commented Jun 12, 2017

Same issue reproduced in a test case here
https://github.com/altus34/webdriver-gecko-issues

@wangliandong
Copy link

hi, my good great developers . could someone tell me a workaround to fix this issue ?
great thanks to all of you folks.

@wangliandong
Copy link

@andreastt , hi , wonderful developer, could you please give some idea ?

@altus34
Copy link

altus34 commented Feb 14, 2018

Still here on year after !!!

Complete test case to reproduce is available here

@whimboo
Copy link
Collaborator

whimboo commented May 9, 2018

As it looks like this issue has been forgotten because no Marionette bug has been filed but it was just tagged here. Before I file a bug let me ask a question. @jimevans could you please try if it works when you use actions to perform such a step? If yes, then we have covered that via https://bugzilla.mozilla.org/show_bug.cgi?id=1418995.

@java123code
Copy link

java123code commented Jun 12, 2018

VS 2017 , Selenium v 3.12.1 ,C# , Firefox V 60.0.2 , Chrome V 66 , Nunit v3.10.1 , Gecko Driver v 20.1 , chrome driver v 2.4

I tried to find solution for Firefox but did not get success :

Below commands are NOT working:

driver.FindElement(By.CssSelector("body")).SendKeys(Keys.F12);

Actions action = new Actions(driver); action.SendKeys(Keys.F12); action.Perform();

Actions action = new Actions(driver); action .KeyDown(Keys.Control).SendKeys(Keys.F12).KeyUp(Keys.Control).Perform();

Actions action = new Actions(driver); action.SendKeys(Keys.F12); action.Click();

@whimboo
Copy link
Collaborator

whimboo commented Jun 18, 2018

@java123code your problem is totally unrelated here given that the key you are trying to send does not contain a shift modifier. Also if you expect that F12 would open the developer tools this won't work because this is not a key which is allowed to be fired from content. It would only be possible with extended chrome privileges. It's similar to Ctrl+T (see issue #786).

@lmtierney
Copy link

@whimboo It still does not work. There's a python test to cover this as well here: https://github.com/SeleniumHQ/selenium/blob/master/py/test/selenium/webdriver/common/w3c_interaction_tests.py#L39

@whimboo
Copy link
Collaborator

whimboo commented Aug 6, 2018

@lmtierney, yes we know. this problem is actually covered by https://bugzilla.mozilla.org/show_bug.cgi?id=1255260.

@lmtierney
Copy link

jimevans could you please try if it works when you use actions to perform such a step?

Just responding for jim :)

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

No branches or pull requests

7 participants