0

Below is the relevant snippet of HTML code :

         </td>                                   
         <td valign=top bgcolor="#dcdcdc" class="camp">
          <script>Oblog()</script>ID <br>


        <input type="text" name="idClnt" size="14" maxlength="11" value='' class="cat" onchange="Camp(this);resetPreScore();" onKeyPress="if (event.keyCode == 13){EnterData();}">

I used the below line of code to enter data

driver.findElement(By.name("idClnt")).sendKeys("10000057W");

I am unable to enter data in the text field . It gives the below error :

"Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not displayed (WARNING: The server did not provide any stacktrace information) "

But the element does not seem to be invisible and i am able to locate the element by using below code :

      List<WebElement> ele = driver.findElements(By.name("idClnt"));

             System.out.println(ele);

It gives the output :

 [[[InternetExplorerDriver: internet explorer on WINDOWS (f319ec27-9201-4536-80a1-fe89689ebe83)] -> name: idClnt], [[InternetExplorerDriver: internet explorer on WINDOWS (f319ec27-9201-4536-80a1-fe89689ebe83)] -> name: idClnt], [[InternetExplorerDriver: internet explorer on WINDOWS (f319ec27-9201-4536-80a1-fe89689ebe83)] -> name: idClnt]]

Kindly suggest how would i be able to enter data in the text field

Vinay
  • 5
  • 1
  • 4

2 Answers2

0

Why don't you use something like?

driver.findElement(By.name("idClnt")).sendKeys("whatever you want to type");

Why are you using list here, if you just want to type data in the input box?

Paras
  • 3,197
  • 2
  • 20
  • 30
0

1) In order to check visibility of element you should use isDisplayed method:

WebElement el = driver.findElement(By.cssSelector("input[class=cat]"));  
System.out.println(el.isDisplayed());

2) Enter text:

WebElement el = driver.findElement(By.cssSelector("input[class=cat]"));
el.sendKeys("SO the best!");

3) If you want to set the value for hidden input try following (in more details https://stackoverflow.com/a/16327185/2517622):

JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement el = driver.findElement(By.cssSelector("input[class=cat]"));
js.executeScript("arguments[0].value = arguments[1];", el, "SO the best!");
Community
  • 1
  • 1
drets
  • 2,583
  • 2
  • 24
  • 38
  • Thanks for the reply !! I used the isDisplayed method and it throws the result as false implying that element is invisible . So i would be needing a way to enter data in hidden field ? – Vinay Dec 21 '15 at 16:11
  • Thanks for the response !! But it does not seem to work also the program just terminates without any error . I tried one of the methods given in (http://stackoverflow.com/questions/11858366/how-to-type-some-text-in-hidden-field-in-selenium-webdriver-using-java?rq=1) . Using that method gives me an error "Element must not be hidden, disabled or read-only" . – Vinay Dec 22 '15 at 11:09