简体   繁体   English

无法使用WebDriver触发输入事件

[英]Unable to trigger input event using WebDriver

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: 其中#client-input-street1是一个简单的输入元素:

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

I have been unable to trigger this 'input' event using WebDriver. 我无法使用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文本框,然后send_keys,然后如所描述的跳格为另一种形式的控制在这里

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: 我尝试使用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. 我尝试单击文本框,然后单击send_keys,然后单击另一个元素。

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. 我正在“输入”处理程序中将某些内容呈现到DOM中,而我的Selenium测试需要检查该动态内容中的某些值。 But I am getting a TimeoutException when waiting for that content to load: 但是在等待该内容加载时出现TimeoutException:

    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. 任何想法,将不胜感激。

This was a bug in my code, not a problem with Selenium. 这是我代码中的错误,不是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). 我在这里发布我的答案,以防它在运行WebDriver时帮助其他发生更改事件的人(在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. 如果在Selenium测试执行期间在任何地方抛出了Javascript异常(并且未捕获到该异常),则它可能会停止Javascript的执行,这可能使事件绑定不发生。 No event bindings, no event getting triggered. 没有事件绑定,没有事件被触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM