SendKeys not working in IE

2,583 views
Skip to first unread message

Jason Skinner

unread,
Oct 11, 2012, 10:11:58 AM10/11/12
to seleniu...@googlegroups.com
Hi all,

I have a script that works great with Chrome.  I try to run it on IE and it doesn't send keys to my textbox.  I am using the webdriver 2.25, java with IE8.  The text box is in an html dialog box that pops up after a button is clicked.  It is not in a different window or frame.

I run the following code:

System.out.println("Size: " + this._driver.findElements(By.id("registrationFirstName")).size());

and it prints

Size: 1

So Selenium is finding the textbox.

When I run:

this._driver.findElement(By.id("registrationFirstName")).sendKeys("TEST");

I get a NoSuchElementException.

Any more ideas on how to get this working or anything else to try to debug this problem?

Thanks
Jason

Jason Skinner

unread,
Oct 11, 2012, 10:18:00 AM10/11/12
to seleniu...@googlegroups.com
Hmmm....I added another line to print the value of the textbox.  It dies too.  So the 2 that are dying use findElement.  The line that is working uses findElements.   So maybe findElement is not working.  Anybody else had any problems with this or have any suggestions?

And correction.  I am using IE 9.


Thanks again,
Jason

Moises Siles

unread,
Oct 11, 2012, 12:54:16 PM10/11/12
to seleniu...@googlegroups.com
hmmm, so if the size method is returning 1,

could you try

this._driver.findElements(By.id("registrationFirstName"))[0].Value or Sendkeys("test")

to see if you got the same error

Jason

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/4u1z87H8wYcJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jason Skinner

unread,
Oct 11, 2012, 1:19:27 PM10/11/12
to seleniu...@googlegroups.com
Correct.  I did it like this:
 
WebElement element = this._driver.findElements(By.id("registrationFirstName")).get(0);
element.sendKeys("test");
 
And that does indeed work.  However it is completely freaking out and doesn't work properly when I try to click on a button in that way.  The expected change does not occur after clicking on the button in this way.
 
Jason 

Moises Siles

unread,
Oct 11, 2012, 1:31:32 PM10/11/12
to seleniu...@googlegroups.com
could you paste the exception?

 
Jason 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/Ml-t9P9xmQQJ.

Jason Skinner

unread,
Oct 11, 2012, 1:40:07 PM10/11/12
to seleniu...@googlegroups.com
org.openqa.selenium.NoSuchElementException: Unable to find element with id == registrationFirstName (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 30.08 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_03'
Driver info: driver.version: RemoteWebDriver
Session ID: 1b80e550-1517-4a80-97d9-2ef91c342514
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
 at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
 at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
 at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:498)
 at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:268)
 at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:297)
 at org.openqa.selenium.By$ById.findElement(By.java:215)
 at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:260)
 at Unvalidated_User.RegistrationPage.register_user(RegistrationPage.java:40)
 at Unvalidated_User.RegistrationPageTest.test_registration(RegistrationPageTest.java:27)
 at Selenium.SeleniumAutomation.registration_test(SeleniumAutomation.java:52)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:601)
 at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
 at org.testng.internal.Invoker.invokeMethod(Invoker.java:715)
 at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:907)
 at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1237)
 at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
 at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
 at org.testng.TestRunner.privateRun(TestRunner.java:767)
 at org.testng.TestRunner.run(TestRunner.java:617)
 at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
 at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
 at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
 at org.testng.SuiteRunner.run(SuiteRunner.java:240)
 at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
 at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
 at org.testng.TestNG.runSuitesSequentially(TestNG.java:1197)
 at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)
 at org.testng.TestNG.run(TestNG.java:1030)
 at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
 at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
 at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

Moises Siles

unread,
Oct 11, 2012, 2:01:53 PM10/11/12
to seleniu...@googlegroups.com
now, could you paste part of the html where that element is located

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/jgmsF06xkJ0J.

Jason Skinner

unread,
Oct 11, 2012, 2:17:29 PM10/11/12
to seleniu...@googlegroups.com
The dialog is hidden until a button is clicked.  My code runs after that button is clicked.
 
<div id="registerDialog" class="hiddenDialog">
 <div id="dialogBackground">&nbsp;</div>
 <div id="innerDialog" class="dialog">
  <div id="page1">
   <div class="closeButton">&nbsp;</div>
   <h1>Join Today</h1>
   <h2>(It will only take a minute)</h2>
   <div class="row clearfix trackFocusEvents">
    <div class="label">First Name</div>
    <div class="value"><input id="registrationFirstName" type="text" /></div>
    <div class="error" id="registrationFirstNameError">&nbsp;</div>
   </div>
   <div class="row clearfix trackFocusEvents">
    <div class="label">Last Name</div>
    <div class="value"><input id="registrationLastName" type="text" /></div>
    <div class="error" id="registrationLastNameError">&nbsp;</div>
   </div>
   <div class="row clearfix trackFocusEvents">
    <div class="label">Zip/Postal Code</div>
    <div class="value"><input id="registrationOfficeZip" type="text" /></div>
    <div class="error" id="registrationOfficeZipError">&nbsp;</div>
   </div>
   <div class="row clearfix trackFocusEvents">
    <div class="label">Country of Practice</div>
    <div class="value">
     <select id="registrationCountryOfPractice">
      <option value="AF">Afghanistan</option>
      <option value="AL">Albania</option>
     </select>
     <input type="hidden" id="registrationCountry" />
     <input type="hidden" id="defaultCountry" value="US" />
    </div>
    <div class="error" id="registrationCountryOfPracticeError">&nbsp;</div>
   </div>
   <div class="row clearfix">
    <div class="label">&nbsp;</div>
    <div class="value credentialsBlock">
     <a id="registrationCredentialsMD" class="credentials formButton" href="javascript:void(0);"><span>MD</span></a>
      <a id="registrationCredentialsDO" class="credentials formButton" href="javascript:void(0);"><span>DO</span></a>
      <a id="registrationCredentialsPA" class="credentials formButton" href="javascript:void(0);"><span>PA</span></a>
      <a id="registrationCredentialsNP" class="credentials formButton" href="javascript:void(0);"><span>NP</span></a>
     <a id="registrationCredentialsOther" class="credentials formButton lastOption" href="javascript:void(0);"><span>Other</span></a>
    </div>
    <div class="error" id="registrationCredentialsError"></div>
   </div>
   <div id="registrationCredentialsOtherOuterDiv" class="row hiddenDialog trackFocusEvents">
    <div class="clearfix">
     <div class="label">&nbsp;</div>
     <div class="value"><input class="hiddenDialog" type="text" id="registrationCredentials" /></div>
    </div>
   </div>
   <div class="row clearfix trackFocusEvents" style="margin-bottom: 11px;">
    <div class="label">Specialty</div>
    <div class="value">
     <select id="registrationSpecialty">
      <option value=""></option>
       <option value="1947">
       Anesthesiology:  general
       </option>
       <option value="1948">
       Anesthesiology: adult cardiothoracic
       </option>
     </select>
    </div>
    <div class="error" id="registrationSpecialtyError"></div>
   </div>
   <div class="clearfix nextButtonRow">
    <table align="center">
     <tbody>
      <tr>
       <td>
        <a id="nextButton" class="smallRoundButton" href="javascript:void(0);"><span>Next</span></a>
       </td>
      </tr>
     </tbody>
    </table>
   </div>
  </div>

Moises Siles

unread,
Oct 11, 2012, 3:25:13 PM10/11/12
to seleniu...@googlegroups.com
hmmm, weird.... I know that is not an iframe, but I just want to try something....

After your buttons is clicked and the new window is displayed, could you Add webdriver.switch("registerDialog"); then add your type method in the registrationFirstName


if that doesn't work, I would add a wait method after the button is clicked, and I'd wait for the registrationFirstName element before execute the sendkeys like this

Click(Button);
waitForElement(registrationFirstName);
SendKeys(registrationFirstName, "My Text")



--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/G8p5uhbflFAJ.

Jason Skinner

unread,
Oct 12, 2012, 9:22:50 AM10/12/12
to seleniu...@googlegroups.com
That didn't work either.  And after getting by this dialog it appears that its all my UI objects, not just textboxes and not just the ones on this dialog.

Looks like findElement isn't working for me.

Thanks for the input.  

Anybody else have any ideas?

Jason

Jason Skinner

unread,
Oct 15, 2012, 12:54:51 PM10/15/12
to seleniu...@googlegroups.com
I don't think that will help.  I am not having a JS issue with IE.  Its a findElement issue.  I still find it strange that findElements works but findElement does not.

And to verify that it wasn't an environment issue, I was able to interact with objects on Google.

Jason


Hien Ngo

unread,
Oct 15, 2012, 1:25:38 PM10/15/12
to seleniu...@googlegroups.com
What do you see?
System.out.println("Size: " + this._driver.findElement(By.id("registrationFirstName")).Displayed.ToString());

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/6RpN22csLK0J.

Jason Skinner

unread,
Oct 15, 2012, 1:57:51 PM10/15/12
to seleniu...@googlegroups.com
System.out.println("Size: " + this._driver.findElement(By.id("registrationFirstName")).IsDispalyed());

Doesn't print anything.  I get the NoSuchElementException.

System.out.println("Size: " + this._driver.findElements(By.id("registrationFirstName")).get(0).IsDispalyed());

Prints Size: true


Jason

Vaibhav

unread,
Dec 11, 2017, 12:55:30 AM12/11/17
to Selenium Users
I am facing same issue with Internet Explorer (IE), similar code is working in Chrome

tried below options but no success

1. 
@FindBy(how=How.XPATH,using="//*[@id='arid_WIN_3_1000000000']") public WebElement Summary;
Summary.sendKeys("Some Text"); --- No Success in IE

2.     
this.Summary.get(0).sendKeys("Some Text"); -- No Success in IE

3. 
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('arid_WIN_3_1000000000').value='Some Text';"); -- This works for IE but not works for Chrome driver

Tried to print and it return True
System.out.println("Size: " + this.driver.findElement(By.id("arid_WIN_3_1000000000")).isDisplayed());

can some one help...
Reply all
Reply to author
Forward
0 new messages