我必须在SelectList
中选择一个选项,然后按一个按钮,我想用C#中的WatiN来做,但如果你有另一个建议,我很乐意听到。
当我通过浏览器从SelectList
中选择一个项目时,一切正常:
working from the browser
但是当我尝试通过C#中的代码执行此操作时,我可以选择SelectList
中的项目,但不会出现提交按钮:
not working from the C# code
网站的来源(未选择项目时):
<form ng-submit="rob()" class="ng-valid ng-dirty">
<select style="max-width: 235px" ng-model="robbery" ng-options="robbery.long_name for robbery in robberies track by robbery.id" class="ng-valid ng-touched ng-dirty"><option value="" class="">[Choose...]</option><option value="1" label="Shoplift - 5% D: 3 SP: 100%">Shoplift - 5% D: 3 SP: 100%</option><option value="2" label="Old lady - 10% D: 10 SP: 100%">Old lady - 10% D: 10 SP: 100%</option><option value="3" label="Car break-in - 10% D: 20 SP: 100%">Car break-in - 10% D: 20 SP: 100%</option><option value="4" label="Taxi - 10% D: 50 SP: 100%">Taxi - 10% D: 50 SP: 100%</option><option value="6" label="House - 10% D: 100 SP: 100%">House - 10% D: 100 SP: 100%</option><option value="7" label="Gas station - 10% D: 200 SP: 100%">Gas station - 10% D: 200 SP: 100%</option><option value="8" label="Grocery store - 10% D: 400 SP: 100%">Grocery store - 10% D: 400 SP: 100%</option><option value="10" label="Kidnapping - 15% D: 800 SP: 100%">Kidnapping - 15% D: 800 SP: 100%</option><option value="11" label="Jewellery - 15% D: 1500 SP: 100%">Jewellery - 15% D: 1500 SP: 100%</option><option value="12" label="Little City Bank - 15% D: 3000 SP: 100%">Little City Bank - 15% D: 3000 SP: 100%</option><option value="14" label="Car Saloon - 15% D: 4000 SP: 100%">Car Saloon - 15% D: 4000 SP: 100%</option><option value="16" label="Local bastards - 25% D: 6000 SP: 100%">Local bastards - 25% D: 6000 SP: 100%</option><option value="26" label="Safety deposit - 25% D: 8000 SP: 100%">Safety deposit - 25% D: 8000 SP: 100%</option><option value="19" selected="selected" label="Rave party - 25% D: 10000 SP: 100%">Rave party - 25% D: 10000 SP: 100%</option></select><br>
<!-- ngIf: robbery.id -->
</form>
<form ng-submit="rob()" class="ng-valid ng-dirty ng-valid-parse">
<select style="max-width: 235px" ng-model="robbery" ng-options="robbery.long_name for robbery in robberies track by robbery.id" class="ng-valid ng-touched ng-dirty ng-valid-parse"><option value="" class="">[Choose...]</option><option value="1" label="Shoplift - 5% D: 3 SP: 100%">Shoplift - 5% D: 3 SP: 100%</option><option value="2" label="Old lady - 10% D: 10 SP: 100%">Old lady - 10% D: 10 SP: 100%</option><option value="3" label="Car break-in - 10% D: 20 SP: 100%">Car break-in - 10% D: 20 SP: 100%</option><option value="4" label="Taxi - 10% D: 50 SP: 100%">Taxi - 10% D: 50 SP: 100%</option><option value="6" label="House - 10% D: 100 SP: 100%">House - 10% D: 100 SP: 100%</option><option value="7" label="Gas station - 10% D: 200 SP: 100%">Gas station - 10% D: 200 SP: 100%</option><option value="8" label="Grocery store - 10% D: 400 SP: 100%">Grocery store - 10% D: 400 SP: 100%</option><option value="10" label="Kidnapping - 15% D: 800 SP: 100%">Kidnapping - 15% D: 800 SP: 100%</option><option value="11" label="Jewellery - 15% D: 1500 SP: 100%">Jewellery - 15% D: 1500 SP: 100%</option><option value="12" label="Little City Bank - 15% D: 3000 SP: 100%">Little City Bank - 15% D: 3000 SP: 100%</option><option value="14" label="Car Saloon - 15% D: 4000 SP: 100%">Car Saloon - 15% D: 4000 SP: 100%</option><option value="16" label="Local bastards - 25% D: 6000 SP: 100%">Local bastards - 25% D: 6000 SP: 100%</option><option value="26" label="Safety deposit - 25% D: 8000 SP: 100%">Safety deposit - 25% D: 8000 SP: 100%</option><option value="19" selected="selected" label="Rave party - 25% D: 10000 SP: 100%">Rave party - 25% D: 10000 SP: 100%</option></select><br>
<!-- ngIf: robbery.id --><input type="submit" ng-if="robbery.id" tabindex="-1" value="Rob the bastard!" class="btn btn-small btn-inverse ng-scope" click-once=""><!-- end ngIf: robbery.id -->
</form>
这是我的C#代码:
_browser.GoTo(gameURL);
WatiN.Core.Form form = _browser.Forms[1];
WatiN.Core.SelectList selectList = form.SelectLists[0];
selectList.Select(selectList.Options[selectList.Options.Count - 2].Text);
我在这里尝试了他们所说的一切:Watin - Submit button remain disabled after filling form