4

I use the sendKeys method to send a string to a search box. The problem is that only the first couple (it differs) of keys are being sent. With the result that the search box is not able to filter content correctly. Below is a snippet of my code:

String currLab = labsInCloud.get(j); //get a lab name from a list
evtFilter_fld.clear(); //clear the filter box
evtFilter_fld.sendKeys(currLab); //send keys to filter box
WebElement selectLab = getDriver().findElement(mainPage_selectLab_i(1)); //select first item from        
                                                                         //filter

so for example if currLab = "test lab" only the "te" of currLab is sent to the filter box.

EDIT: Just to add that selectLab is selecting the incorrect item due to the full text not being sent.

5
  • What is evtFilter_fld in HTML ? Input box, text area ? Commented Oct 22, 2014 at 16:23
  • Does it have a maxlength like this <input type="text" id="x" maxlength="2"> ? Commented Oct 22, 2014 at 16:26
  • no it doesnt. I can manually type in text of any length Commented Oct 22, 2014 at 16:27
  • You can try to use "test lab" instead of currLab ... to see what is happening. Commented Oct 22, 2014 at 16:36
  • ya, ive been debuggin it for a bit now and have no joy! i'll step away from it, tomorrow is a new day! Commented Oct 22, 2014 at 16:59

3 Answers 3

2

I encountered this issue and it was a problem with my keyboard mapping.

My particular case was when running tests in a desktop environment over VNC. I was using tightvncserver and it was loading keyboard incorrectly. Switching to vnc4server resolved the problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Same issue here. But I could not do apt install for vnc4server on Ubuntu 20.04 so I decided to go with tiger vnc server. All keyboard problems solved now.
1

I had the same problem. Sometimes only a char in a 3-char string would be put in before it clicked the button.

I added the following workaround:

'blah'.split('').forEach((c) => element.sendKeys(c))

It is a bit slower than inputing all at once, but faster than a constant timeout, and it works.

Found the tip at https://github.com/angular/protractor/issues/1511 (it is closed since it is not a protractor issue)

You can also try the javascript approach

String theText = "asdf"    
((JavascriptExecutor) driver).executeScript("arguments[0].value='" + theText + "';", fieldElement);

1 Comment

this works 100%, idk why some fields do not allow us to enter all the characters
0

It looks like i wasnt giving the driver enough time to send the keys. I added a sleep(1000) before attempting to select and item. Working fine now.

2 Comments

wierd, I never had an issue with it even tho sending some very long strings
I'm not exactly sure that it was an issue with time, but it seems like the only reasonable assumption to make, given that sleep() resolved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.