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

SendKeys() behavior is inconsistent and broken - often moving focus to the end of an input value erroneously #2141

Open
MJB222398 opened this issue Oct 25, 2023 · 4 comments

Comments

@MJB222398
Copy link

System

  • Version: GeckoDriver: 0.33.0
  • Platform: Ubuntu 20.04
  • Firefox: 118.0.2 (64-bit)
  • Selenium: .NET 4.13.1

Testcase

I have a text input that has some contents. I am intending to overwrite its value with a new value:

var input = driver.FindElement(inputIdentifier);
var newValue = "Some new text";

new Actions(driver)
    .SendKeys(input, Keys.Home)
    .KeyDown(Keys.Shift)
    .SendKeys(input, Keys.End)
    .KeyUp(Keys.Shift)
    .SendKeys(input, newValue)
    .Build()
    .Perform();

But it is not behaving as it should. This should highlight the existing text (its single line input rather than text area if that matters) and then type the new value thus overwriting the highlighted existing value. What tends to happen though is that focus moves to the end of the existing input value before it then types the new one. This code works as intended on Chromium. Have tried a few other way including using the DEL key to delete the highlighted text, Ctrl+ A to highlight instead etc. but result is the same. The behaviour doesn't even appear to be deterministic, it works 50% of the time if the existing value is just alpha numeric characters. However if there are '-' in there is never works fully, sometimes it will highlight a portion up to the next hyphen (rather than the full value) and other times it will just stick the new value on the end.

@whimboo
Copy link
Collaborator

whimboo commented Oct 25, 2023

Could you please attach a trace-level log from geckodriver?

@MJB222398
Copy link
Author

@whimboo I tried but I've not been able to get them. I set the log level to Trace on my FirefoxOptions but nothing relevant is being printed to standard out. I am using Selenium docker with a Selenium Hub and then (among others) a Firefox node. Was looking at the logs on the FF node and I'm not seeing anything from the geckodriver there?

Only seeing:

12:45:54.844 WARN [SeleniumManager.lambda$runCommand$1] - Exception managing firefox: Unable to discover proper geckodriver version in offline mode
12:45:56.558 INFO [LocalNode.newSession] - Session created by the Node. Id: 4c8b3b0c-92de-4bb4-bd99-50e973254ace, Caps: Capabilities {acceptInsecureCerts: false, browserName: firefox, browserVersion: 118.0.2, moz:accessibilityChecks: false, moz:buildID: 20231009140911, moz:firefoxOptions: {args: [-profile, home/seluser/.mozilla/firef...], binary: /usr/lib/firefox/firefox.sh, log: {level: trace}}, moz:geckodriverVersion: 0.33.0, moz:headless: false, moz:platformVersion: 5.15.90.1-microsoft-standar..., moz:processID: 2000, moz:profile: /home/seluser/.mozilla/fire..., moz:shutdownTimeout: 60000, moz:webdriverClick: true, moz:windowless: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:bidiEnabled: false, se:cdp: ws://172.18.0.5:4444/sessio..., se:noVncPort: 7900, se:vnc: ws://172.18.0.5:4444/sessio..., se:vncEnabled: true, se:vncLocalAddress: ws://172.18.0.5:7900, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
12:46:07.474 INFO [SessionSlot.stop] - Stopping session 4c8b3b0c-92de-4bb4-bd99-50e973254ace

@whimboo
Copy link
Collaborator

whimboo commented Oct 25, 2023

Hm, we have seen similar issues with C# recently, and maybe something changed in Selenium in how to generate the logs. Maybe you could ask there for some hint? Also can you reproduce this problem locally as well?

@MJB222398
Copy link
Author

MJB222398 commented Oct 25, 2023

@whimboo Apologies for the wait. I can't use Firefox locally at work so had to wait until I got home where I can't use the actual code I wrote at work so had to write some quick rubbish to replicate it.... Was able to replicate the same issue running against a local geckodriver. So running this terrible code:

var profile = new FirefoxProfile();
profile.SetPreference("security.sandbox.content.level", 5);
var driver = new RemoteWebDriver(new Uri("http://localhost:4444/"), new FirefoxOptions
{
    Profile = profile,
    LogLevel = FirefoxDriverLogLevel.Trace
});

driver.Navigate().GoToUrl("https://inputtypes.com/");

Thread.Sleep(4000);

var input = driver.FindElementByClassName("input-item__display-input");

new Actions(driver).SendKeys(input, "Some text to enter").Build().Perform();

new Actions(driver)
    .SendKeys(input, Keys.Home)
    .KeyDown(Keys.Shift)
    .SendKeys(input, Keys.End)
    .KeyUp(Keys.Shift)
    .Build()
    .Perform();

new Actions(driver)
    .SendKeys(input, "Some different text value")
    .Build()
    .Perform();

This resulted in the value of the input being "Some text to enterSome different text value". It should of course be "Some different text value" as it would be if you manually performed the actions.

I get the logs pasted in below. Not sure why they are all 'DEBUG' level? As you can see in the code above I set the level to 'TRACE'.

1698269655294 geckodriver::marionette DEBUG Connection to Marionette established on 127.0.0.1:49495.
1698269656978 webdriver::server DEBUG <- 200 OK {"value":{"sessionId":"647d6761-7ae1-4070-bc6e-26e688b079e2","capabilities":{"acceptInsecureCerts":false,"browserNa ... ctability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"}}}
1698269657006 webdriver::server DEBUG -> POST /session/647d6761-7ae1-4070-bc6e-26e688b079e2/url {"url":"https://inputtypes.com/"}
1698269657758 webdriver::server DEBUG <- 200 OK {"value":null}
1698269661784 webdriver::server DEBUG -> POST /session/647d6761-7ae1-4070-bc6e-26e688b079e2/element {"using":"css selector","value":".input\-item__display\-input"}
1698269661799 webdriver::server DEBUG <- 200 OK {"value":{"element-6066-11e4-a52e-4f735466cecf":"8f6764fd-8dde-42f4-8fe6-e13a76462c2e"}}
1698269661812 webdriver::server DEBUG -> POST /session/647d6761-7ae1-4070-bc6e-26e688b079e2/actions {"actions":[{"type":"pointer","id":"default mouse","parameters" ... },{"type":"keyDown","value":"e"},{"type":"keyUp","value":"e"},{"type":"keyDown","value":"r"},{"type":"keyUp","value":"r"}]}]}
1698269662281 webdriver::server DEBUG <- 200 OK {"value":null}
1698269662286 webdriver::server DEBUG -> POST /session/647d6761-7ae1-4070-bc6e-26e688b079e2/actions {"actions":[{"type":"pointer","id":"default mouse","parameters" ... 0},{"type":"pause","duration":0},{"type":"keyDown","value":""},{"type":"keyUp","value":""},{"type":"keyUp","value":""}]}]}
1698269662944 webdriver::server DEBUG <- 200 OK {"value":null}
1698269677428 webdriver::server DEBUG -> POST /session/647d6761-7ae1-4070-bc6e-26e688b079e2/actions {"actions":[{"type":"pointer","id":"default mouse","parameters" ... },{"type":"keyDown","value":"u"},{"type":"keyUp","value":"u"},{"type":"keyDown","value":"e"},{"type":"keyUp","value":"e"}]}]}
1698269677848 webdriver::server DEBUG <- 200 OK {"value":null}

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

2 participants