
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Clear Text Entered in Selenium with Python
We can enter text on any field in Selenium. After entering the text, we may need to remove or clear the text we entered in that field. This interaction with the web elements can be achieved with the help of clear() method.
Thus a clear() method is used to clear or reset an input field belonging to a form/ edit box. It replaces the text content on that particular element of the page.
Syntax
driver.find_element_by_xpath("//input[class ='gsc-search']").clear()
Example
Code Implementation with clear() 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/current_affairs.htm") #to refresh the browser driver.refresh() # identifying the edit box and entering text in edit box driver.find_element_by_xpath("//*[@class='gsc-input']"). send_keys("Selenium") # clears the content driver.find_element_by_xpath("//*[@class='gsc-input']").clear() #to close the browser driver.close
Advertisements