Reading about Python? Actually practice it. Try PyChallenge free

Python Tutorial

selenium textbox

Given a webpage containing a text area or text field, text can be automatically written using Python code. In this article we will demonstrate this automation using a small code snippet.

Related course
Practice Python with interactive exercises

Selenium add textbox text We start by importing the selenium module. The driver needs to be created starting the web browser. We open the target website using the method

driver.get(url)

We select the html element using the method

driver.find_element_by_id(id)

Then we write text in the box using the method:

send_keys(str)

Complete code:

from selenium import webdriver
import time

options = webdriver.ChromeOptions() options.add_argument('--ignore-certificate-errors') options.add_argument("--test-type") options.binary_location = "/usr/bin/chromium" driver = webdriver.Chrome(chrome_options=options) driver.get('http://codepad.org')

text_area = driver.find_element_by_id('textarea') text_area.send_keys("This text is send using Python code.")

The browser will start automatically adding the text:

selenium textbox send_keys method writes in textbox

BackNext