Coconote
AI notes
AI voice & video notes
Try for free
⌨️
Entering Text in Input Fields without `sendKeys`
Jul 12, 2024
Entering Text in Input Fields without
sendKeys
Overview
Three methods for entering text without
sendKeys
:
Action Class
JavaScript Executor
Robot Class
Method 1: Action Class
Create an action object.
Use the
sendKeys
method of Action Class (not Selenium's library class).
Steps:
Create Action object.
Find the input field element.
Use the
sendKeys
method with the Action object.
Method 2: JavaScript Executor
Utilize JavaScript to directly set value of the input field.
Steps:
Create a JavaScript executor.
Find the input field element.
Use JavaScript to set the value.
Method 3: Robot Class
Use Robot class to simulate keyboard operations.
Important Note: Works on the currently focused screen only.
Risk: If the test loses focus, text may be entered in a different application (e.g., Notepad).
Steps:
Create Robot class object.
Ensure the correct screen is visible and focused.
Use Robot class methods to type text.
Practical Demonstration
Examples provided using Google Maps input field.
Testing all methods and verifying their functionality.
Action Class method: Verified and working.
JavaScript Executor method: Verified and working.
Robot Class method: Verified and working, but must ensure correct screen is focused.
Summary
These methods provide alternatives to
sendKeys
for entering text in Selenium.
Suitable depending on the specific needs and constraints of the application.
📄
Full transcript