Selenium sendKeys (string) method sending only part of a string

I am using a method sendKeys

to post a string to a search box. The problem is that only the first pair (it is different) of keys is sent. As a result, the search box will not be 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 "te" currLab is sent in the filter field.

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

+3


source to share


3 answers


Looks like I didn't give the driver enough time to send the keys. I added sleep (1000) before trying to select and item. Now we are working fine.



0


source


I had the same problem. Sometimes, just a char will be put into a 3 char string before the button is pressed.

I've added the following workaround:

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

      

It's slightly slower than putting all of them at once, but faster than constant timeout and it works.



Found a review at https://github.com/angular/protractor/issues/1511 (it's closed since it's not a protractor issue)

You can also try the javascript approach

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

      

+1


source


I ran into this issue and it is a keyboard mapping issue.

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

0


source







All Articles