Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用WatiN测试下拉列表_C#_Visual Studio 2010_Watin - Fatal编程技术网

C# 使用WatiN测试下拉列表

C# 使用WatiN测试下拉列表,c#,visual-studio-2010,watin,C#,Visual Studio 2010,Watin,我正在使用WatiN来测试一个网站并自动化一个过程。我可以成功打开网站,但是当我尝试从选择列表中选择选项时出现问题: <select id="form:Dropdown" name="form:Dropdown" size="1" title="Select Option"> <option value="0">Select Code</option> <option value="234890/NA/1">23FA4890</opt

我正在使用WatiN来测试一个网站并自动化一个过程。我可以成功打开网站,但是当我尝试从选择列表中选择选项时出现问题:

<select id="form:Dropdown" name="form:Dropdown" size="1" title="Select Option"> <option value="0">Select Code</option>
    <option value="234890/NA/1">23FA4890</option>
    <option value="237014/NA/1">23FA7014</option>
</select>

这看起来应该可以工作,但我一直收到一个错误“等待240秒元素显示时超时”。

我认为您不需要调用
WaitUntilExists
,因为
WaitForComplete
在页面完全加载之前已经将被阻止。我知道这并不能完全回答您的问题,但我想向您展示一个我在生产中使用了一年多但从未出现过问题的代码示例

注意,我正在从iframe中抓取一个帧,并从下拉列表中选择“ID”的值:

Regex regex = new Regex(@"^.*\/globalframeset\.esp.*$");
using (var browser = IE.AttachTo<IE>(Find.ByUrl(regex), 12))
{
    if (browser != null)
    {
        browser.AutoClose = false;

        var iFrame = browser.Frame(Find.ById("GlobalWrapper"));

        if (iFrame != null)
        {
            var frame = iFrame.Frame(Find.ByName("frGlobalNav"));

            if (frame != null)
            {
                frame.TextField(Find.ByName("findtext")).Value = person.MedicalRecordNumber;

                // This code is setting the DDL called "filtertype" to a value of "ID"
                frame.SelectList(Find.ByName("filtertype")).SelectByValue("ID");

                Regex buttonRegex = new Regex(@"^.*\/go_text\.gif.*$");
                frame.Image(Find.BySrc(buttonRegex)).ClickNoWait();
            }
        }

        browser.BringToFront();
    }
}
Regex Regex=new Regex(@“^.*\/globalframeset\.esp.*$”;
使用(var browser=IE.AttachTo(Find.ByUrl(regex),12))
{
如果(浏览器!=null)
{
browser.AutoClose=false;
var iFrame=browser.Frame(Find.ById(“GlobalWrapper”);
if(iFrame!=null)
{
var frame=iFrame.frame(Find.ByName(“frGlobalNav”);
如果(帧!=null)
{
frame.TextField(Find.ByName(“findtext”)).Value=person.MedicalRecordNumber;
//此代码正在将名为“filtertype”的DDL设置为“ID”值
frame.SelectList(Find.ByName(“filtertype”)).SelectByValue(“ID”);
Regex buttonRegex=newregex(@“^.*\/go_text\.gif.*$”;
frame.Image(Find.BySrc(buttonRegex)).ClickNoWait();
}
}
browser.BringToFront();
}
}

您是否能够通过值选择它(使用
SelectByValue
方法)?@AdamPlocher错误出现在SelectList上,因此我甚至没有尝试过通过值选择选项。正如另一个注意事项一样,您是否尝试过通过
FindByName
来查看是否获得更好的结果?我在下面贴了一个答案,可能有用,也可能没用:)@AdamPlocher仍然不工作。当我尝试FindByName时出现同样的错误。你使用的是什么版本的IE?
Regex regex = new Regex(@"^.*\/globalframeset\.esp.*$");
using (var browser = IE.AttachTo<IE>(Find.ByUrl(regex), 12))
{
    if (browser != null)
    {
        browser.AutoClose = false;

        var iFrame = browser.Frame(Find.ById("GlobalWrapper"));

        if (iFrame != null)
        {
            var frame = iFrame.Frame(Find.ByName("frGlobalNav"));

            if (frame != null)
            {
                frame.TextField(Find.ByName("findtext")).Value = person.MedicalRecordNumber;

                // This code is setting the DDL called "filtertype" to a value of "ID"
                frame.SelectList(Find.ByName("filtertype")).SelectByValue("ID");

                Regex buttonRegex = new Regex(@"^.*\/go_text\.gif.*$");
                frame.Image(Find.BySrc(buttonRegex)).ClickNoWait();
            }
        }

        browser.BringToFront();
    }
}