Selenium webdriver can enter keypresses or type on any webpage. Selenium is the Python module to automate web browsers. The web driver is connected to both the web browser and the Python code.
The selenium webdriver starts the browser, the browser loads the webpage, selects the textbox and types.
To use keypress in selenium, first you need to import some stuff from the selenium module:
from selenium.webdriver.common.by import By
In the example below, a web browser is started. Then it searches for an HTML element by its id (elements often have a unique id). We grab the html element by its unique identifier like this:
Then the method .send_keys() is used to type into the element. Don’t forget to also send the enter or return key if necessary.
The selenium keyboard code example below does all that. In this example it does an automated searh on wikipedia, but the principle works on any site.
# -*- coding: utf-8 -*-
If you are new to selenium, then I highly recommend this book.