1

I'm trying to automate box, that displays and auto updates data under it depending on what you type into it.

For example, when I type "Joh" it will display "John One" "John Two" in drop down menu, as soon as I have typed at least 3 letters into box.

When I type with keyboard it works fine, but when I use SendKeys("Joh"), no auto update happens, no data is shown.

Using waits or sending only one letter at a time didn't help.

What could cause it? Are there some other options to send text that could work in this case?

4
  • I tried: SendKeys(John) > SendKeys(keys.backspace) >SendKeys(n), for example- but that also did not work
    – George
    Commented May 16, 2016 at 16:03
  • 1
    At a guess, your page has JavaScript code to search dynamically on any keypress, and SendKeys does not trigger the event that triggers the search. You're going to need to find the JavaScript code that populates your dropdown menu, then work out how to force Selenium to trigger that specific event.
    – Kate Paulk
    Commented May 16, 2016 at 16:38
  • @George can you scroll through a list after text is entered? sounds like you may need to implement it like a dropdown select.
    – DEnumber50
    Commented May 16, 2016 at 16:41
  • I would suggest looking into running JavascriptExecuter in your script to kick off the js that will do the auto update after the third letter is typed (could put it in a loop so it runs after every subsequent letter as well)
    – Swagin9
    Commented May 16, 2016 at 20:22

5 Answers 5

2

"At a guess, your page has JavaScript code to search dynamically on any keypress, and SendKeys does not trigger the event that triggers the search. You're going to need to find the JavaScript code that populates your dropdown menu, then work out how to force Selenium to trigger that specific event." – Kate Paulk 17 hours ago

This worked, i got event to trigger using selenium.interactions.Actions to simulate keyDown/Up (which was needed for autoupdate to trigger) after sending text with sendKeys

Using JSExecutor or EventFiringWebDriver didnt work in this case.

Heres an example in C#:

        var a = new Actions(driver);
        a.KeyDown(Keys.LeftShift).KeyUp(Keys.LeftShift);
        var s = a.Build();
        s.Perform();
1
  • Helpful answer, but can you provide code. All the key down and key up info I find is for arrow keys.
    – User
    Commented Dec 24, 2017 at 5:16
1

Instead if using WebDriver use the EventFiringWebDriver and sendkeys will work without any issue and fire the text change event as well.

3
  • Can you explain why?
    – FDM
    Commented May 17, 2016 at 5:30
  • 1
    Because WebDriver is designed in a way that it instantly performs the action but EventFiringWebdriver is designed in a way that it tries to simulate exact user interaction and fires the associated events. Commented May 17, 2016 at 7:36
  • 1
    The event firing is on the code side, not the browser side. EFWD allows you to place listeners on events and perform actions every time one happens.
    – Paul Muir
    Commented May 17, 2016 at 11:05
0

Autoupdate happens AFTER you finish typing, right? I think you need to end the string with TAB ("\t") to leave the input field, so all related events can fire.

1
  • No, it updates during typing
    – George
    Commented May 16, 2016 at 15:54
0

I think you need to inspect to know which event fire when typing on the textbox, try to fire that event using JS or JQuery, then force Selenium execute script.

0

I reccomend after SendKeys to fire an event fireEvent(locator, blur).

From documentation:

fireEvent(locator, eventName)
Arguments:
    locator - an element locator
    eventName - the event name, e.g. "focus" or "blur"
Explicitly simulate an event, to trigger the **corresponding "onevent" handler**.

SendKeys does not do the same thing as your keyboard does and the text is injected by Selenium javascipts, but no key is really pressed.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.