Closed codingphil closed 6 years ago
action.send_keys(Keys.CONTROL,"a").perform()
does not work as expected.
Adding a Keys.NULL at the end does.
action.send_keys(Keys.CONTROL,"a",Keys.NULL).perform()
Why is the behavior different from WebElement.sendKeys()
?
When I perform the same test with WebElement.sendKeys()
it works fine.
This test fails too with org.junit.ComparisonFailure: expected:<[]> but was:<[12345a]>
(geckodriver 0.16, FF 53)
// given
driver.navigate().to(TestPages.SIMPLETEXTFIELDPAGE);
WebElement textFieldElem = driver.findElementByName("textfield");
textFieldElem.click();
new Actions(driver).sendKeys(textFieldElem, "12345").perform();
assertEquals("12345", textFieldElem.getAttribute("value"));
// when
new Actions(driver).sendKeys(Keys.CONTROL, "a", Keys.NULL).perform();
new Actions(driver).sendKeys(Keys.DELETE).perform();
// then
assertEquals("", textFieldElem.getAttribute("value"));
I’m sorry, it’s not clear to me from the comments so far in this thread what the problem actually is. I have some questions:
Keys.NULL
at the end?sendKeys
not work at all?sendKeys
also work if you append Keys.NULL
?Does the action API work only if you append Keys.NULL at the end? Does sendKeys not work at all? Or does sendKeys also work if you append Keys.NULL?
In general Actions.sendKeys()
works fine for normal characters like "abc" (even without Keys.NULL
at the end).
Pressing Ctrl-A via Actions.sendKeys()
does not work.
Neither with or without the Keys.NULL
.
Both test cases mentioned in the comments above fail.
Interestingly the following code without using the Actions API does work (without using Keys.NULL
):
// given
webDriver.navigate().to(TestPages.SIMPLETEXTFIELDPAGE);
WebElement textFieldElem = webDriver.findElementByName("textfield");
textFieldElem.click();
textFieldElem.sendKeys("12345");
assertEquals("12345", textFieldElem.getAttribute("value"));
// when
List<CharSequence> keyWithModifiers = new ArrayList<CharSequence>();
keyWithModifiers.add(Keys.CONTROL);
keyWithModifiers.add("a");
String ctrlA = Keys.chord(keyWithModifiers);
textFieldElem.sendKeys(ctrlA);
textFieldElem.sendKeys(Keys.DELETE);
// then
assertEquals("", textFieldElem.getAttribute("value"));
Same issue on newer gecko driver. VERSIONS Firefox version: 53.0 (64-bit) GeckoDriver: v0.16.1 win64 Selenium: 3.4.0 Java bindings NetBeans: 8.1 Java jdk1.8.0_73
PLATFORM Windows 7 64 bit 16GB RAM
CODE
WebElement element = webDriver.findElement(By.id("search-box"));
element.sendKeys("hello");
Actions builder = new Actions(webDriver);
builder.sendKeys(Keys.chord(Keys.CONTROL, "a")).perform();
builder.sendKeys(Keys.chord(Keys.CONTROL, "c")).perform();
webDriver.close();
EXPECTED text "hello" availale in the system clipboard
ACTUAL text "helloac" appears in input element.
LOG EXTRACT
1494326268054 Marionette TRACE conn0 -> [0,3,"findElement",{"using":"css selector","value":"#search\\-box"}]
1494326268061 Marionette TRACE conn0 <- [1,3,null,{"value":{"element-6066-11e4-a52e-4f735466cecf":"47bf754c-7277-46df-86e1-9436f4855f77","ELEMENT":"47bf754c-7277-46df-86e1-9436f4855f77"}}]
1494326268062 geckodriver::marionette TRACE � [1,3,null,{"value":{"element-6066-11e4-a52e-4f735466cecf":"47bf754c-7277-46df-86e1-9436f4855f77","ELEMENT":"47bf754c-7277-46df-86e1-9436f4855f77"}}]
1494326268062 webdriver::server DEBUG � 200 OK {"value":{"element-6066-11e4-a52e-4f735466cecf":"47bf754c-7277-46df-86e1-9436f4855f77"}}
1494326268075 webdriver::server DEBUG → POST /session/1e564606-3df9-4d4f-b7cb-af4007beb957/element/47bf754c-7277-46df-86e1-9436f4855f77/value {"id":"47bf754c-7277-46df-86e1-9436f4855f77","text":"hello","value":["h","e","l","l","o"]}
1494326268076 geckodriver::marionette TRACE → 116:[0,4,"sendKeysToElement",{"id":"47bf754c-7277-46df-86e1-9436f4855f77","text":"hello","value":["h","e","l","l","o"]}]
1494326268078 Marionette TRACE conn0 -> [0,4,"sendKeysToElement",{"id":"47bf754c-7277-46df-86e1-9436f4855f77","text":"hello","value":["h","e","l","l","o"]}]
1494326268143 Marionette TRACE conn0 <- [1,4,null,{}]
1494326268144 geckodriver::marionette TRACE � [1,4,null,{}]
1494326268144 webdriver::server DEBUG � 200 OK {"value": {}}
1494326268161 webdriver::server DEBUG → POST /session/1e564606-3df9-4d4f-b7cb-af4007beb957/actions {"actions":[{"type":"key","actions":[{"type":"keyDown","value":""},{"type":"keyUp","value":""},{"type":"keyDown","value":"a"},{"type":"keyUp","value":"a"},{"type":"keyDown","value":""},{"type":"keyUp","value":""}],"id":"default keyboard"}]}
1494326268162 geckodriver::marionette TRACE → 275:[0,5,"performActions",{"actions":[{"actions":[{"type":"keyDown","value":""},{"type":"keyUp","value":""},{"type":"keyDown","value":"a"},{"type":"keyUp","value":"a"},{"type":"keyDown","value":""},{"type":"keyUp","value":""}],"id":"default keyboard","type":"key"}]}]
1494326268164 Marionette TRACE conn0 -> [0,5,"performActions",{"actions":[{"actions":[{"type":"keyDown","value":""},{"type":"keyUp","value":""},{"type":"keyDown","value":"a"},{"type":"keyUp","value":"a"},{"type":"keyDown","value":""},{"type":"keyUp","value":""}],"id":"default keyboard","type":"key"}]}]
1494326268182 Marionette TRACE conn0 <- [1,5,null,{}]
1494326268183 geckodriver::marionette TRACE � [1,5,null,{}]
1494326268183 webdriver::server DEBUG � 200 OK {"value": {}}
1494326268189 webdriver::server DEBUG → POST /session/1e564606-3df9-4d4f-b7cb-af4007beb957/actions {"actions":[{"type":"key","actions":[{"type":"keyDown","value":""},{"type":"keyUp","value":""},{"type":"keyDown","value":"c"},{"type":"keyUp","value":"c"},{"type":"keyDown","value":""},{"type":"keyUp","value":""}],"id":"default keyboard"}]}
1494326268190 geckodriver::marionette TRACE → 275:[0,6,"performActions",{"actions":[{"actions":[{"type":"keyDown","value":""},{"type":"keyUp","value":""},{"type":"keyDown","value":"c"},{"type":"keyUp","value":"c"},{"type":"keyDown","value":""},{"type":"keyUp","value":""}],"id":"default keyboard","type":"key"}]}]
1494326268191 Marionette TRACE conn0 -> [0,6,"performActions",{"actions":[{"actions":[{"type":"keyDown","value":""},{"type":"keyUp","value":""},{"type":"keyDown","value":"c"},{"type":"keyUp","value":"c"},{"type":"keyDown","value":""},{"type":"keyUp","value":""}],"id":"default keyboard","type":"key"}]}]
1494326268213 Marionette TRACE conn0 <- [1,6,null,{}]
1494326268215 geckodriver::marionette TRACE � [1,6,null,{}]
1494326268215 webdriver::server DEBUG � 200 OK {"value": {}}
codingphil workaround also works for me.
Could someone test if that is still a problem with Firefox 58 beta, or 59 Nightly?
The test is still failing with Firefox 58 Beta and Firefox 59 Nightly, geckodriver 0.19.1 and selenium 3.8.1.
I don't know which kind of code you were running for the trace from the last comment. Can you please highlight the part of the trace log which shows the problem?
The code from the original bug entry:
// given
driver.navigate().to("http://localhost/SimpleTextField.html"); // TODO: Adapt to your own local server
WebElement textFieldElem = driver.findElementByName("textfield");
textFieldElem.click();
new Actions(driver).sendKeys(textFieldElem, "12345").perform();
assertEquals("12345", textFieldElem.getAttribute("value"));
// when
List<CharSequence> keyWithModifiers = new ArrayList<CharSequence>();
keyWithModifiers.add(Keys.CONTROL);
keyWithModifiers.add("a");
String ctrlA = Keys.chord(keyWithModifiers);
new Actions(driver).sendKeys(textFieldElem, ctrlA).perform();
new Actions(driver).sendKeys(Keys.DELETE).perform();
// then
assertEquals("", textFieldElem.getAttribute("value")); // <<=== FAILS
The problem is that the assert fails (no error in trace). I just added the trace if anybody needs the info.
Now I see. This looks indeed strange in the trace:
{"type":"keyDown","value":""},{"type":"keyUp","value":""},{"type":"keyDown","value":"a"}, {"type":"keyUp","value":"a"},{"type":"keyDown","value":""},{"type":"keyUp","value":""}
The Ctrl keys gets released before pressing a
, and pressed/released again afterward. Given that chord()
is not part of geckodriver, it should be a problem with the Selenium binding you are using. It just generates wrong code which then gets passed to geckodriver. CC @mjzffr
I assume code like the following will work, right?
action.keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).perform();
It should make it a dupe of issue #1112.
Interesting is that the following code works fine.
List<CharSequence> keyWithModifiers = new ArrayList<CharSequence>();
keyWithModifiers.add(Keys.CONTROL);
keyWithModifiers.add("a");
String ctrlA = Keys.chord(keyWithModifiers);
textFieldElem.sendKeys(ctrlA);
textFieldElem.sendKeys(Keys.DELETE);
So is the chord wrong here too?
Which code works fine? The one I posted in my last comment? Have you run that? If it works (which I believe it does) this issue is invalid, and you should file a bug for your used binding.
My argument was that in the code posted above (https://github.com/mozilla/geckodriver/issues/665#issuecomment-355338378) Keys.chord() works fine because it is passed to WebElement.sendKeys() so it does not seem to be a bug in the method Keys.chord(). When using Keys.chord() with the Actions API (Actions.sendKeys()) it does not work. So where and what exactly is the bug?
Once againcord
is not part of geckodriver/webdriver, and it seems to export wrongly for actions. See the following line from your trace log:
1515067064121 webdriver::server DEBUG -> POST /session/204a18cc-522c-43e0-89c9-43f8b4ff8f06/actions {"actions":[{"id":"default mouse","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"duration":100,"x":0,"y":0,"type":"pointerMove","origin":{"ELEMENT":"4ef273d9-927d-476f-b8cf-d63f87d97819","element-6066-11e4-a52e-4f735466cecf":"4ef273d9-927d-476f-b8cf-d63f87d97819"}},{"button":0,"type":"pointerDown"},{"button":0,"type":"pointerUp"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"}]},{"type":"key","actions":[{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"duration":0,"type":"pause"},{"type":"keyDown","value":""},{"type":"keyUp","value":""},{"type":"keyDown","value":"a"},{"type":"keyUp","value":"a"},{"type":"keyDown","value":""},{"type":"keyUp","value":""}],"id":"default keyboard"}]}
geckodriver/webdriver itself gets already the wrong sequence. So it's not us failing here.
Marking as dupe of issue #1112.
I haven’t followed the conversation, but does this mean there is an upstream Selenium issue here?
Yes, there is. @codingphil could you file an issue for that?
@whimboo Are you sure it is not geckodriver issue ? I can see Chrome driver works fine with action.sendKeys(Keys.chord(Keys.CONTROL, "a")).perform(); with the same version Selenium. I think it should be a geckodriver defect. Can you confirm ?
I am having a similar issue. It works fine when using the Chrome driver. But the same code for Gecko, I get this error: Failed: POST /session/0d56f0a4-cd98-42fa-bf89-4275b9ed9f08/keys did not match a known command
(I'm using Protractor)
Adding Key.NULL
like this: browser.actions().sendKeys(Key.chord(Key.CONTROL, "a", Key.NULL)).perform();
does not fix the issue for me.
Doing this: browser.actions().keyDown(Key.CONTROL).sendKeys("a").keyUp(Key.CONTROL).perform();
does not fix the issue for me.
Both of those workarounds work fine in Chrome, but not in Firefox.
First there is no end-point for keys
defined in the spec:
https://w3c.github.io/webdriver/webdriver-spec.html#list-of-endpoints
As such your mentioned POST
request will indeed not work. Without seeing a trace log (also in regards the other cases, I would say that this could be a Protractor problem.
Also note that the chromedriver by default does not speak the W3C protocol, while geckodriver is doing that by default. I could believe that turning on w3c mode in chromedriver would also cause a failure.
@codingphil have you had a chance to file a Selenium issue for that problem?
List
can any one suggest me , this code make it as one or two lines.
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have run into an issue you think is related, please open a new issue.
Firefox Version
53.0 (64bit) geckodriver 0.15
Platform
Windows 10 Anniversary Update (Redstone 1)
Steps to reproduce -
When sending "Ctrl-A" to
Actions.sendKeys(elem, keys)
the Ctrl key seems to be not pressed (just the 'a' character). The Ctrl-A is created viaKeys.chord()
.Sending other non-modifier special keys like Backspace works fine.
Maybe related to #233.
The following unit test fails with:
org.junit.ComparisonFailure: expected:<[]> but was:<[12345a]>
The same test works fine with Google Chrome.