华廷不能选择从列表中选择一个选项 [英] Watin can't select an option from a select list

查看:115
本文介绍了华廷不能选择从列表中选择一个选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(这是JavaScript的控制领料单)。输出选择列表格式的样本;

I am using WATIN to complete a dynamically created form, which can contain several SelectLists (these are javascript controlled picklists). A sample of the select list format outputted is;

<select title=" " style="width: 300px;" 
    name="NameHere" 
    data-bind="value: NameHere.AnswerCode"
    class="fieldInputElement pickList">
    <option selected="" value=""></option>
    <option class="answerTextWithNote" value="A">alpha</option>
    <option class="answerTextWithNote" value="B" data-guidance="E.g. minor ">bravo</option>
    <option class="answerTextWithNote" value="C" data-guidance="E.g. b">charlie</option>
    <option class="answerTextWithNote" value="C" data-guidance="E.g. c">chatlie</option>
</select>

不幸的是,华廷似乎无法在列表中选择任何选项,返回一个错误。

Unfortunately, watin seems to fail to select the list and any options, returning an error.

在code

window.SelectList(Find.ByName("NameHere")).Options[2].Select();

返回有关该指数的错误,虽然

Returns an error about the index, although

string y = window.SelectList(Find.ByName("NameHere")).Option(x[1].ToString()).ToString();

将为索引选项分配正确的值。

will assign the correct value for the indexed option.

谁能告诉我如何触发选择,因为我已经尝试焦点()和所有的keydown没有喜悦。

Can anyone advise me on how to trigger the select, as i have tried on focus() and keydown all without joy.

选择列表使用选择了插件,如果这能帮助?

The selectlist is using the 'Chosen' plugin, if this helps?

推荐答案

以下是有点不pretty ....但...它的工作原理。

The following is somewhat not pretty.... but... it works.

使用

  • IE8
  • WatiN 2.0
  • NUnit
  • Chosen example here: http://davidwalsh.name/dw-content/jquery-chosen.php

我无法重现你的索引错误;我可以通过索引访问选择列表的选项没有问题(见下文code)。但是...访问它们在为选上都有自己的presentation标记没有帮助。

I was unable to reproduce your index error; I can access the SelectList options by index without issue (see code below). BUT... accessing them didn't help at as Chosen has its own presentation markup.

所以,相反我的工作与所选择的HTML元素,而不是选择列表,事情正在改善。

So, instead I worked with the Chosen HTML elements instead of the SelectList and things are working better.

[Test]
public void ChosenTest()
{
    IE myIE = new IE(true);
    myIE.GoTo("http://davidwalsh.name/dw-content/jquery-chosen.php");

    myIE.SelectList(Find.ByClass("chosen chzn-done")).WaitUntilExists();  //Needed as sometimes the controls were not fully loaded; unable to get item not found exceptions once this was added.

    Console.WriteLine("ByIndex:" + myIE.SelectList(Find.ByClass("chosen chzn-done")).Options[3].Text);   //To show no index out of bounds error.
    //  Just for reference --> myIE.SelectList(Find.ByClass("chosen chzn-done")).Options[3].Select();  //Has no effect.

    string id = myIE.SelectList(Find.ByClass("chosen chzn-done")).Id;
    myIE.Div(id + "_chzn").Div(Find.ByClass("chzn-drop")).ElementWithTag("li", Find.ByIndex(3)).Click();
    myIE.Div(id + "_chzn").Links[0].Spans[0].Click();  //Needed or the SelectList-ish stays open.
}

查找ByClass做的控件ID改变的例子页面上。
该WaitUntilExists消除了间歇性故障。

Finding ByClass was done as the control IDs change on the example page. The WaitUntilExists eliminated the intermittent failures.

这篇关于华廷不能选择从列表中选择一个选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆