- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to enter values in an edit box in Selenium with python?
We can enter values in an edit box in Selenium with the help of the methods listed below −
Using the send_keys method.
This method can send any text to an edit box or perform pressing keys with the help of Keys class.
Using the Javascript executor.
Javascript Document Object Model can work with any of the elements on the page. Javascript works on the client side and performs actions on the web page. Selenium can execute a Javascript script with the help of execute_script() method. We can enter values on any edit box with the help of this method.
Example
Code Implementation with send_keys method.
from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke #actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/index.htm") #to refresh the browser driver.refresh() # identifying the edit box and entering text with send_keys method driver. find_element_by_css_selector("input[class='gsc-input']"). send_keys("Selenium") #to close the browser driver.close()
Code Implementation with Javascript executor.
from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke #actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/index.htm") #to refresh the browser driver.refresh() # enter text with the Javascript executor driver.execute_script( "document.getElementsByName('search')[0].value = 'Selenium' ;") #to close the browser driver.close()
- Related Articles
- How to press ENTER inside an edit box in Selenium?
- How do you enter text in the edit box in Selenium?
- How to input letters in capital letters in an edit box in Selenium with python?
- How to enter a letter in uppercase in the edit box using Actions in Selenium?
- How to reset or clear an edit box in Selenium?
- How to get the value of the edit box in Selenium?
- How to key in values in input text box with Javascript executor in Selenium with python?
- How to simulate pressing enter in html text input with Selenium?
- How to fetch values from a webelement in Selenium with python?
- How to edit a JavaScript alert box title?
- How to get all the values in a worksheet in Selenium with python?
- How to edit values of an object inside an array in a class - JavaScript?
- How to upload a file in Selenium with no text box?
- How to specify "ENTER" button functionality in Selenium WebDriver code?
- Get value of an input box using Selenium (Python)

Advertisements