How to locate and insert a value in a text box (input) using Python Selenium?


I have the following HTML structure and I am trying to use Selenium to enter a value of NUM:

<div class="MY_HEADING_A">
    <div class="TitleA">My title</div>
    <div class="Foobar"></div>
        <div class="PageFrame" area="W">                
             <span class="PageText">PAGE <input id="a1" type="txt" NUM="" />  of <span id="MAX"></span> </span>

Here is the code I have written:

head = driver.find_element_by_class_name("MY_HEADING_A")
frame_elem = head.find_element_by_class_name("PageText")

# Following is a pseudo code. 
# Basically I need to enter a value of 1, 2, 3 etc in the textbox field (NUM) 
# and then hit RETURN key.
## txt  = frame_elem.find_element_by_name("NUM")
## txt.send_keys(Key.4)

How to get this element and enter a value???????? ???????????????

This question is tagged with python python-2.7 selenium-webdriver form-submit html-input

~ Asked on 2013-09-01 09:59:01

The Best Answer is


Assuming your page is available under ""

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()

Select element by id:

inputElement = driver.find_element_by_id("a1")

Now you can simulate hitting ENTER:


or if it is a form you can submit:


~ Answered on 2013-09-01 11:33:23

Most Viewed Questions: