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.

6
  • do you got any exceptions? Commented Apr 10, 2016 at 17:27
  • Yes, I updated the question with the exception I am getting. Commented Apr 10, 2016 at 19:39
  • Can you check whether your input field located inside <iframe>? Commented Apr 11, 2016 at 7:01
  • It is not. There are no iframes on the page. Commented Apr 11, 2016 at 13:39
  • Look at the second answer in this Stackoverflow Q&A. Commented Apr 11, 2016 at 14:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.