Python hosting: Host, run, and code Python in the cloud!
Given a webpage containing a text area or text field, text can be automatically written using Python code.
Python can start a web browser, open the page and write code in it.
This is done with the the selenium framework.
Browser Automation with Python Selenium
In this article we will demonstrate this automation using a small code snippet.
Start by importing the selenium module. This module is not installed by default, so if you don’t have it install it with the Python package manager (pip).
pip install selenium
The driver needs installed aswell as the web browser.
Lets take a look at the code. First you need the webdriver to create the web browser. You can open the target website using the method below
where the parameter specfies the website url.
We select the html element using the method find_element_by_id. The html element must have an id for this to work, otherwise you need xpath.
Then the browser writes text in the textbox using the method send_keys, as parameter it takes a string:
The complete code example:
The browser will start automatically and starts adding the text to the textbox: