- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to send keyboard input to a textbox on a webpage using Python Selenium webdriver?
We can send keyboard input to a textbox on a webpage in Selenium webdriver in Python using the method send_keys. The text to be entered is passed as a parameter to that method.
To perform keyboard actions, we can also use the send_keys method and then pass the class Keys.<key to be pressed> as a parameter to that method. To use the Keys class, we have to add from selenium.webdriver.common.keys import Keys statement to the code.
Syntax
i = driver.find_element_by_name("txt") i.send_keys("Selenium") i.send_keys(Keys.RETURN)
Let us try to send keyboard input to a textbox on a page −
Example
from selenium import webdriver from selenium.webdriver.common.keys import Keys #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch URL driver.get("https://www.google.com/") #identify text box l = driver.find_element_by_class_name("gLFyf") #send input l.send_keys("Selenium") #send keyboard input l.send_keys(Keys.RETURN)
Output
- Related Articles
- How to refresh a webpage using Python Selenium Webdriver?
- How to send a report through email using Selenium Webdriver?
- Is it possible to scroll down in a webpage using Selenium Webdriver programmed on Python?
- How can I verify Error Message on a webpage using Selenium Webdriver?
- How can I clear text of a textbox using Python Selenium WebDriver?
- How to get typed text from a textbox by using Selenium Webdriver?
- How to type in textbox using Selenium WebDriver with Java?
- How to click on a link using Selenium webdriver in Python.
- How to send cookies with selenium webdriver?
- How to loop through a menu list on a webpage using Selenium?
- How to open a new window on a browser using Selenium WebDriver for python?
- How to close a Python figure by keyboard input using Matplotlib?
- How can I handle multiple keyboard keys using Selenium Webdriver?
- Send keys without specifying element in Python Selenium webdriver
- How to click on image in selenium webdriver Python?

Advertisements