-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[js]: Fix sendKeys command fail on FileDetector.handleFile error. #14663
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
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|
cc: @harsha509 @pujagani |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @garg3133 !
|
Somehow got the tests working locally and without the change made in this PR, the added test failed with the below error (as expected): So, the added test is working correctly. cc: @AutomatedTester |

User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
When using the
.sendKeyscommand with a file detector, if the promise returned by thehandleFilemethod of file detector results in a rejection, the control moves to the catch clause and then to the lastthis.execute_function call.Now, the problem with this flow is that in case of the
handleFileerror, thekeysvariable remains anArrayas opposed to it being converted to a string ifhandleFileruns without any error. But, the lastthis.execute_function call expectskeysto be a string.This results in
keys.split is not a functionerror when the flow goes through thecatch()clause.So, this PR fixes this issue by converting
keysto string if the flow goes through thecatchclause so that the lastthis.execute_always receiveskeysin a string format, as expected.Motivation and Context
One of the Nightwatch.js users is facing an issue due to this: nightwatchjs/nightwatch#4280. They are using a remote file detector (
new require('selenium-webdriver/remote').FileDetector()) in their test and when they try to send a large block of text to a text input using the.sendKeyscommand, they are getting thekeys.split is not a functionerrorPlease check this comment for more detailed analysis. tl;dr: Sending long text using
.sendKeyswith the file detector enabled leads toENAMETOOLONGerror which is not handled by the remote file detector'shandleFilemethod, causing the method to be rejected, due to which the control flow lands inside thecatch()clause inwebdriver.js > sendKeyswithkeysvariable still anArray, and using the.splitmethod on an Array leads to thekeys.split is not a functionerror.Types of changes
Checklist
PR Type
Bug fix, Tests
Description
sendKeyscommand where an error inhandleFilewould cause akeys.split is not a functionerror by ensuringkeysis converted to a string in the catch block.sendKeyswhen the file detector'shandleFilemethod rejects, ensuring robust error handling.Changes walkthrough 📝
webdriver.js
Fix `sendKeys` command to handle file detector errors correctlyjavascript/node/selenium-webdriver/lib/webdriver.js
keysto a string in the catch block.keysis always a string before callingthis.execute_.webdriver_test.js
Add test for `sendKeys` handling file detector errorsjavascript/node/selenium-webdriver/test/lib/webdriver_test.js
sendKeyswith a file detector handlingerrors.
sendKeysfunction behaves correctly whenhandleFilerejects.