Shiva Krishna Chippa
Shiva Krishna Chippa

Reputation: 688

How to clear inserted strings from multiple text boxes using Selenium web driver

I've sent keys to the set of textboxes in a registration form from 1st column of excel sheet. When I was trying to sent keys from 2nd column of excel sheet, these are appended to existing strings. We can clear them one by one using findElement(By.id("xyz")).clear. But I want to clear all text boxes at a time. Do we have any logic for that. Please help me. It is freaking me since a few hours.

I tried below login also, but thrown exception:

List<webelement> list1 = driver.findElement(By.className("tab1")).findElements(By.tagName("input"));

for(i=0; i < list1.size(); i++)
{
    List1.get(i).clear;
}

Exception: Element is not currently visible and so may not be interacted with Command duration or timeout: 32 milliseconds

Upvotes: 1

Views: 996

Answers (2)

Shiva Krishna Chippa
Shiva Krishna Chippa

Reputation: 688

I got it!!!

I've stored all text fields in single list with its Class names, they all have same class name.

List<WebElement> List1 = driver.getElements(By.ClassName("xyz"));
for(i=0;i<List1.size();i++)
{
List1.get(i).clear
}

Upvotes: 1

mfsi_krushnas
mfsi_krushnas

Reputation: 151

Check , if all of these items are under a form then using JS reset method, you can reset.

document.getElementById("myForm").reset();

Execute it under javascriptExecutor.

You can also try to apply some html code to the source where all fields are present and reset them using JS during runtime.

It cant be achieved using only selenium. Hope it helps.

Upvotes: 0

Related Questions