- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 clear the 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.
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
- Related Articles
- Clear text from textarea with selenium.
- How to get entered text from a textbox in selenium?
- How can I clear text of a textbox using Python Selenium WebDriver?
- How to use text() in xpath in Selenium with python?
- How to get text with selenium web driver in python?
- How to read a text file in Selenium with python?
- How to write a text file in Selenium with python?
- How to clear the text field part of ttk.Combobox in tkinter?
- Clear browser Cookies with Selenium WebDriver Java bindings.
- How to reset or clear an edit box in Selenium?
- How to simulate pressing enter in html text input with Selenium?
- How to upload a file in Selenium with no text box?