- Selenium Webdriver Tutorial
- Home
- Introduction
- Installation
- Browser Navigation
- Identify Single Element
- Identify Multiple Elements
- Explicit and Implicit Wait
- Pop-ups
- Backward and Forward Navigation
- Cookies
- Exceptions
- Action Class
- Create a Basic Test
- Forms
- Drag and Drop
- Windows
- Alerts
- Handling Links
- Handling Edit Boxes
- Color Support
- Generating HTML Test Reports in Python
- Read/Write data from Excel
- Handling Checkboxes
- Executing Tests in Multiple Browsers
- Headless Execution
- Wait Support
- Select Support
- JavaScript Executor
- Chrome WebDriver Options
- Scroll Operations
- Capture Screenshots
- Right Click
- Double Click
- Selenium Webdriver Useful Resources
- Selenium WebDriver - Quick Guide
- Selenium WebDriver - Useful Resources
- Selenium WebDriver - Discussion
Selenium Webdriver - Handling Edit Boxes
Selenium can be used to input text to an edit box. An edit box is represented by the input tag and its type attribute should have the value as text. It can be identified with any of the locators like - id, class, name, css, xpath and tagname.
To input a value into an edit box, we have to use the method send_keys.
Let us see the html code of a webelement −
The edit box highlighted in the above image has a tagname - input. Let us try to input some text into this edit box after identifying it.
Code Implementation
The code implementation for handling edit box is as follows −
from selenium import webdriver #set chromedriver.exe path driver = webdriver.Chrome(executable_path='../drivers/chromedriver') #url launch driver.get("https://www.tutorialspoint.com/index.htm") #identify edit box with tagname l = driver.find_element_by_tag_name('input') #input text l.send_keys('Selenium Python') #obtain value entered v = l.get_attribute('value') print('Value entered: ' + v) #driver close driver.close()
Output
The output shows the message - Process with exit code 0 meaning that the above Python code executed successfully. Also, the value entered within the edit box (obtained from the get_attribute method) - Selenium Python gets printed in the console.
To Continue Learning Please Login
Login with Google