
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 from TextArea with Selenium
We can clear text from a text area with Selenium. We shall use the clear method to remove the content from a text area or an edit box. First we shall identify the text area with the help of any locator.
A text area is identified with textarea tagname in the html code. Let us input some text inside the below text area, then clear the text.
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class TextAreaClear{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://www.uitestpractice.com/Students/Form"); // identify element WebElement m = driver.findElement(By.id("comment")); // enter text m.sendKeys("Selenium"); // obtain value entered in text area System.out.println("Value entered: " + m.getAttribute("value")); // clear text area m.clear(); // obtain value entered in text area after clear applied System.out.println("Value after clear(): " + m.getAttribute("value")); driver.quit(); } }
Output
Advertisements