Collections 如何通过同一参数传递不同的集合?
我正在创建一个方法,该方法将采用不同类型(div、span..)的集合并对其进行搜索。但我找不到传递不同集合类型的参数。我尝试了IElementContainer和ElementCollections,但我无法将DivCollection转换为这两种。还有别的办法吗 执行搜索的方法:Collections 如何通过同一参数传递不同的集合?,collections,parameter-passing,watin,Collections,Parameter Passing,Watin,我正在创建一个方法,该方法将采用不同类型(div、span..)的集合并对其进行搜索。但我找不到传递不同集合类型的参数。我尝试了IElementContainer和ElementCollections,但我无法将DivCollection转换为这两种。还有别的办法吗 执行搜索的方法: private static ElementCollection searchCollections(IElementContainer ec, WACore.compStringInfo info)
private static ElementCollection searchCollections(IElementContainer ec, WACore.compStringInfo info)
{
if (info.componentIDName == WACore.componentIDs.Id.ToString())
{
return ec.Elements.Filter(Find.ById(info.componentIDValue));
}
else if (info.componentIDName == WACore.componentIDs.Name.ToString())
{
return ec.Elements.Filter(Find.ByName(info.componentIDValue));
}
else if (info.componentIDName == WACore.componentIDs.Title.ToString())
{
return ec.Elements.Filter(Find.ByTitle(info.componentIDValue));
}
else if (info.componentIDName == WACore.componentIDs.OuterText.ToString())
{
String str = info.componentIDValue.Substring(1, 6);
return ec.Elements.Filter(Find.ByText(new Regex(str)));
}
else
{
return null;
}
}
来电者:
例如,发布您的方法代码。正如我所看到的,SpanCollection和DivCollection扩展了BaseElementCollection,可能只需要在方法中指定一个参数-BaseElementCollection。谢谢,我发布了代码。按照这种方式,我在调用搜索方法的运行时得到一个强制转换错误。前几天我查看了BaseElementCollection,但它要求指定一个类型。搜索参数需要一般地接受任何元素集合(Div,span…)PS:我试图完成的是创建一种方法来查找给定元素类型ex:Div和属性ex的元素;Id=“myDiv”doc是一个IElementContainer吗?你从他那里得到了Divs系列并把它投给了IElementContainer?可能只是搜索集合(doc.Elements、info);
return searchCollections((IElementContainer)doc.TextFields, info);
return searchCollections((IElementContainer)(doc.Divs), info);
return searchCollections((IElementContainer)doc.Spans, info);