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.
source to share
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);
source to share