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.
Related course:
keyboard
selenium keyboard
To use keypress in selenium, first you need to import some stuff from the selenium module:
1 | 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:
1 | input=browser.find_element_by_id("searchInput") |
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.
1 | input.send_keys("Python") |
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.
1 | # -*- coding: utf-8 -*- |
If you are new to selenium, then I highly recommend this book.