Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium sendKeys doesnt input all text

I'm trying to write e2e tests for our application based on angular and angular material. We are using chromedriver 2.16, selenium 2.46 and the newest protractor.net. The problem is, when I want to use sendKeys method, selenium doesn't send all of them all the time - it's random, sometimes it sends the whole value, sometimes 1-3 characters.

Here is the code: 1st with selenium

var nameInput = webDriver.FindElement(By.Id('SizeTemplateName'));
    nameInput.Click();
    nameInput.Clear();
    nameInput.SendKeys('some random value 123 456 789');

2nd with protractor.net

var nameInput = angularWebDriver.FindElement(NgBy.Model('vm.sizeTemplate.name'));
    nameInput.Click();
    nameInput.Clear();
    nameInput.SendKeys('some random value 123 456 789');

None of the approaches work. Any ideas?

like image 959
Patryk Wojtasik Avatar asked Feb 15 '26 06:02

Patryk Wojtasik


1 Answers

I had same problem. Try to use this

private static void sendKeys(IWebElement element, string text)
{
    element.Click();
    Actions actions = new Actions(driver);
    foreach (char c in text)
    {
        actions.SendKeys(c.ToString())
            .Perform();
    }
}

Usage in code

sendKeys(nameInput, "some random value 123 456 789")
like image 192
Tomáš Kukučka Avatar answered Feb 17 '26 20:02

Tomáš Kukučka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!