-1

I am trying to enter text into input box using sendkeys or javascript. I can see value entered into input field but when clicking on search button then I am getting an error message that input field cannot be blank.

html is

input id="inputMId" class="" type="text" data-bind="value: mId, onMFieldFocusOut: MId,css{datePicker:isMIdError()}" maxlength="15"
span class="validationMessage" style="display: none;"
span id="MErrorMessage" class="validationMessage" data-bind="text:mErrorMessage,visible:isVisibleMErrorMessage()" style="display: none;"



The code I tried is

element.sendKeys("value") 


and

JavascriptExecutor js = (JavascriptExecutor)getDriver();
js.executeScript("document.getElementById('inputMId').value='"+testData.get("MId")+"';"); 



I am trying this on Internet Explorer 11 using serenity framework.
Above code works perfectly fine on chrome

SachinB
  • 348
  • 6
  • 18

2 Answers2

0

I have encountered a similar problem with IE a quick work around I used was to

  • Use the java script executor to scroll the element into view
  • Perform a SendKeys() action
  • Put focus on the text field
  • Lastly take focus off (blur) the element

I use this to try replicate actual user interactions

Although I would be interested to know the reason why a simple SendKeys() action will work on Chrome but not IE

0

At the end, below things worked for me.

Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable stringSelection = new StringSelection(myString);
clpbrd.setContents(stringSelection, null);
element.click();
Robot r;
try {
r = new Robot();
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_V);
r.keyRelease(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_V);
} catch (AWTException e) {
e.printStackTrace();
}

I am not sure whether this code will run successfully using Jenkins or not, locally it is working very fine

SachinB
  • 348
  • 6
  • 18