问题描述
我有两个输入,如下所示:
I have two inputs as follows:
第一
<input type="text" class="form-control ng-isolate-scope ng-valid-date ng-animate ng-dirty ng-valid ng-valid-required" name="measurementDate" id=
"measurementDate" placeholder="MM/DD" datepicker-popup="MM/dd" min="01/01/2014" max="12/31/2016" datepicker-options="{"showWeeks":false,"yearRange":3}" ng-model="acawiz.data.standardPeriodStart" ng-change="acawiz.setStandardStabilityPeriodStart()" is-open="acawiz.measurementPickerIsOpen" style="">
第二
<input type="text" class="form-control ng-isolate-scope ng-pristine ng-valid-required ng-valid ng-valid-date" name="stabilityDate" id="stabilityDate" placeholder="MM/DD" show-weeks="false" datepicker-popup="MM/dd" min="01/01/2014" max="12/31/2016" datepicker-options="{"showWeeks":false,"yearRange":3}" ng-model="acawiz.data.standardStabilityPeriodStart" ng-change="acawiz.standardStabilityPeriodStartChanged()" is-open="acawiz.stabilityPickerIsOpen" ng-required="true" readonly="" required="required">
使用日期选择器(作为最终用户)填充这些日期.但是,对于Selenium
测试,我决定绕过日期选择器,因为这会使测试变得更加脆弱.为了解决该问题,我最初考虑删除required
和readonly
属性,并使用sendKeys()
输入日期,我成功了.我还尝试设置它们两者的value属性,并看到更改发生在以下地方:
Those dates are populated by using date picker(as an end user). But, for Selenium
tests I decided to bypass date picker since that can make the tests flakier. To solve the issue I initially thought to remove the required
and readonly
attributes and use sendKeys()
to input the dates and I was successful. I also tried to set the value property of both of them and I see the changes take place with the following:
string value = Convert.ToDateTime(date).ToString("MM/dd");
string setValueProp = @"document.getElementById('measurementDate').value = '" + value + "'";
ExecuteJavaScript(setValueProp);
但是,当我单击完成向导时,我看不到我在日期中所做的更改,可能的原因是ng-change="acawiz.standardStabilityPeriodStartChanged()"
从未触发过.有没有办法可以通过上面的javascript代码相应地触发ng-change?
However, when I click finish the wizard I do not see the changes I made in dates and the possible reason is because ng-change="acawiz.standardStabilityPeriodStartChanged()"
never even triggered. Is there a way I can trigger the ng-change accordingly with the javascript code above?
推荐答案
以编程方式更改模型(如您所做的那样)时,不会触发ng-change
事件.我认为您将必须手动调用change事件.
When you change the model programmatically (like you are doing) then ng-change
event is not triggered. I think you will have to manually call the change event.
string value = Convert.ToDateTime(date).ToString("MM/dd");
string setValueProp = @"$('#measurementDate').val('" + value + "').trigger('change');";
ExecuteJavaScript(setValueProp);
这篇关于使用硒触发Angular页面的ng-change的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!