无法通过Selenium驱动程序设置knockout js app的输入值

时间:2015-12-18 14:13:42

标签: javascript jquery selenium knockout.js capybara

我使用Selenium驱动程序和Capybara与外部网站进行交互,外部网站编码 Knockout JS

任务是设置输入值。是的,这么简单。这是这个愚蠢的输入的HTML:

<input data-bind="value: $root.data.location.user_address,
                  valueUpdate: 'input', 
                  css: {'arenda-input_error': $root.validator.fieldsErrors['location.user_address']().length || $root.data.location.noResults()},
                  event: {keyup: function (data, event) {$root.data.location.onKeyUp(event); return true;},
                  blur: function () {$root.data.location.onBlur(); return true;}}" 
       placeholder="Минск, проспект Дзержинского, 5" 
       class="arenda-input arenda-input_full-width new-sub__input arenda-input_error"
       type="text">

我已经尝试了什么?

find('.new-sub__location-input').set 'My value'

什么都没发生

page.execute_script %Q{$('.new-sub__location-input').val('My value').trigger('change')}

什么都没发生

find('.new-sub__location-input').native.send_keys 'My value'

同样的事情

发生了什么事?如何设置此输入的值?

1 个答案:

答案 0 :(得分:0)

显示的所有尝试似乎都使用与您显示的输入元素不同的css类。如果您对问题的html是正确的,则以下内容应该有效

find(:css, '.new-sub__input').set('My value')

或者因为fill_in可以使用占位符属性

fill_in("Минск, проспект Дзержинского, 5", with: 'My value')