-1

I am using sendkeys() to fill the form in my application. When I try to submit the form with all the values in the fields are correct and as per the requirement the form fails to submit. But when i key press the input, the field accepts the values. Can someone please help to overcome this issue? Below is the snippet of the code I use:

WebElement fname = driver.findElement(By.id("txtFirstName"));
fname.clear();
fname.sendKeys("Test");

Below is the html,

<input name="ctl19$ctl20$ctl00$txtFirstName" type="text" maxlength="50"
 id="ctl19_ctl20_ctl00_txtFirstName" tabindex="182" class="DTC_txtStandard"
 onchange="DealerTrackCanada.CommonObjects.Util.ExtenderContr‌​ols.DataChangeEventM‌​anager.onApplicantNa‌​meChange('ctl19_ctl2‌​0_ctl00_txtFirstName‌​', 'ctl19_ctl20_ctl00_txtMiddleName', 'ctl19_ctl20_ctl00_txtLastName');" 
 oldbgc="rgb(255, 255, 153)" style="background-color: rgb(153, 204, 255);">
krokodilko
  • 35,300
  • 7
  • 55
  • 79
Sarav ACC
  • 1
  • 2
  • The field accepts the values or not? Is it throwing any exception? Share the HTML of the element as well please. – Reez0 Nov 07 '17 at 18:41
  • In some browsers, you need to "focus" on the element first and then you can send keys – Danylo Zatorsky Nov 07 '17 at 19:06
  • Hi, No Its not throwing any exceptions. Below is the html, – Sarav ACC Nov 07 '17 at 19:27
  • 1
    Your code is interacting with element `By.id("txtFirstName")` but you have shown us HTML of element `id="ctl19_ctl20_ctl00_txtFirstName"`. There are two completely different elements. – krokodilko Nov 07 '17 at 21:25
  • As krokodilko said earilier in the comments. You're using the wrong id element. You have to do this to reach the element you want WebElement fname = driver.findElement(By.id("ctl19_ctl20_ctl00_txtFirstName")); – Ali Nov 07 '17 at 23:45
  • I actually use the same element Id as it is in HTML. when I added it I shortened it. If that is the case I should be getting element not found error. – Sarav ACC Nov 08 '17 at 15:16

1 Answers1

0

You can use JavaScriptExecutor

   WebElement fname =      driver.findElement(By.id("txtFirstName"));                                

     JavascriptExecutor executor = (JavascriptExecutor)driver;
       executor.executeScript("arguments[0].click();", fname);
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36