0

I have an event handler defined like so:

$('#client-input-street1').on('input', function() {
    console.debug('street1 text changed');

    // Do some other dynamic stuff
});

Where #client-input-street1 is a simple input element:

<input id="client-input-street1" type="text" value="">

I have been unable to trigger this 'input' event using WebDriver. I have tried all manner of techniques such as tabbing to the #client-input-street1 textbox, then send_keys, then tabbing to another form control as described here:

street1_input = self.driver.find_element_by_id('client-input-street1')
street1_input.send_keys('3229 NW Pittock Dr')
street1_input.send_keys(Keys.TAB)

I have tried explicitly setting the value using Javascript:

self.driver.execute_script("document.getElementById('client-input-street1').setAttribute('value', '3229 NW Pittock Dr')")

I have tried clicking the text box, then send_keys, then clicking another element.

I am rendering some content into the DOM inside the 'input' handler, and my Selenium test needs to check some values inside that dynamic content. But I am getting a TimeoutException when waiting for that content to load:

    ec = EC.presence_of_element_located((By.ID, 'client-address-suggestions-list'))
    address_suggestions_list = wait.until(ec)

Nothing has worked so far. Any ideas would be appreciated.

Community
  • 1
  • 1
John Cleveland
  • 488
  • 5
  • 17
  • do you got any exceptions? – Andersson Apr 10 '16 at 17:27
  • Yes, I updated the question with the exception I am getting. – John Cleveland Apr 10 '16 at 19:39
  • Can you check whether your input field located inside ` – Andersson Apr 11 '16 at 07:01
  • It is not. There are no iframes on the page. – John Cleveland Apr 11 '16 at 13:39
  • Look at the second answer in this [Stackoverflow Q&A](http://stackoverflow.com/questions/4689969/onchange-event-does-not-get-fired-on-selenium-type-command). – MikeJRamsey56 Apr 11 '16 at 14:33
  • Thanks to both of you for your help. I have fixed the issue, it was a bug in my code, rather than a problem with Selenium. I followed the second answer in that link, which led me down a path that helped me discover a Javascript exception that was getting thrown by the page right before the onchange handler was being bound, so the onchange handler was never actually getting bound as the test was running. – John Cleveland Apr 12 '16 at 13:31

1 Answers1

0

This was a bug in my code, not a problem with Selenium. I'm posting my answer here in case it helps someone else with change events not firing when running WebDriver (of which there are many questions on StackOverflow). If a Javascript exception gets thrown anywhere during execution of your Selenium test (and the exception isn't caught), it may stop execution of your Javascript, which may make your event bindings not occur. No event bindings, no event getting triggered.

John Cleveland
  • 488
  • 5
  • 17