Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.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# 将新链接添加到LinkCollection WatIn_C#_Asp.net_Watin - Fatal编程技术网

C# 将新链接添加到LinkCollection WatIn

C# 将新链接添加到LinkCollection WatIn,c#,asp.net,watin,C#,Asp.net,Watin,我有20个链接的div,但我只需要包含href=“.do?”的链接,所以我不知道如何选择链接集合的链接。所以我做的是全部取20,如果它们包含href,并且如果(真)尝试插入到新的链接集合,则检查1乘1,但失败,我无法添加到新的链接集合 我的代码 LinkCollection TempLinksOfAccounts = browser.Div(Find.ByClass("module")).Links; LinkCollection LinksOfAccounts; int in

我有20个链接的div,但我只需要包含href=“.do?”的链接,所以我不知道如何选择链接集合的链接。所以我做的是全部取20,如果它们包含href,并且如果(真)尝试插入到新的链接集合,则检查1乘1,但失败,我无法添加到新的链接集合

我的代码

 LinkCollection TempLinksOfAccounts = browser.Div(Find.ByClass("module")).Links;
    LinkCollection LinksOfAccounts;
    int index = 0;
    for (int i = 0; i < TempLinksOfAccounts.Count; i++)
       {
        string Href = TempLinksOfAccounts[i].GetAttributeValue("href");

       if (Href.Contains("account-details.go?adx"))
            {
                               //Here i trying to do
LinksOfAccounts[index]=TempLinksOfAccounts[i];//fail
LinksOfAccounts.Add(TempLinksOfAccounts[i]);//fail
 LinksOfAccounts[index].Link=TempLinksOfAccounts[i];//fail
index++;

             }
         }
LinkCollection TempLinksOfAccounts=browser.Div(Find.ByClass(“模块”)).Links;
链接收集链接帐户;
int指数=0;
对于(int i=0;i
您不能直接创建链接集合,您需要使用其构造函数,它将返回链接集合

var finder = new NativeElementFinder(
() => browser.Body.NativeElement.AllDescendants,
browser.DomContainer,
new[] { ElementTag.Any },
Find.By("href", new System.Text.RegularExpression.Regex(@"*account-details.go?adx*")));

LinkCollection lc = new LinkCollection(browser.DomContainer, finder);

现在lc将拥有所有包含href的链接,如finder查询中所述。您可以根据需要修改finder查询。

Hmmm。。。count=0,我认为这是因为Find.By(“href”,“account details.go?adx”),我的href不等于account details.go?adx,它具有附加值,可以更改每个时间的帐户详细信息。go?adx=1a2b3x,我需要像使用代码一样使用contains。如何将Find.By(“href”,“account details.go?adx”)更改为contains(“href”,“account details.go?adx”)?您可以使用正则表达式来解决该问题。我已经用正则表达式更新了我上面的帖子。或者您也可以使用下面的代码
LinkCollection lc=browser.Links.Filter(l=>l.GetAttributeValue(“href”).Contains(“account details.go?adx”)