html二次点击锚掉失效,无法再次单击锚标记

我正在编写一个抓取程序。

我第一次能够点击锚标签,但是一旦我再次循环同样没有发生。我在IE的Watin实例中完成了这个。我怀疑这是因为我已经完成了IE实例的后面。

请找到两段代码。

下载PDF的方法

private void DownloadFiles(IE ieInstance, HTMLDocument document_sub)

{

// int chktest = 2;

try

{

foreach (HTMLAnchorElement anchorTagPg1 in document_sub.getElementsByTagName("a"))

{

if (anchorTagPg1.innerText.Contains("Monthly Statement"))

{

string urltemp = anchorTagPg1.outerHTML.ToString();

int startTextpos = urltemp.IndexOf("window.open");

string spltstr1 = urltemp.Substring(startTextpos);

int endpos = spltstr1.IndexOf(')');

string spltstr2 = spltstr1.Substring(0, endpos);

spltstr2 = spltstr2.Replace("window.open(", "");

string[] manipulatestrsplt = spltstr2.Split(',');

string finalmanipstr = manipulatestrsplt[0].Replace("'", "");

finalmanipstr = finalmanipstr.Replace("amp;", "");

finalurl = "https://myaccount.pseg.com/psegbdisu/" + finalmanipstr;

//anchorTagPg1.click();

//ieInstance.WaitForComplete();

ieInstance.GoToNoWait(finalurl);

Thread.Sleep(5000);

SendKeys.SendWait("^%S"); // to get the Save As window...

Thread.Sleep(5000);

SendKeys.SendWait("abc123");

Thread.Sleep(5000);

SendKeys.Send("^S");

Thread.Sleep(5000);

SendKeys.SendWait("DownloadedFile" + iFileCnt + ".pdf"); // Enters File Name

Thread.Sleep(5000);

SendKeys.Send("{ENTER}");

iFileCnt++;

//chktest++;

Thread.Sleep(5000);

ieInstance.Back();

// bool rtnBack = ieInstance.Back();

Thread.Sleep(10000);

// }

}

}

}

catch (Exception ex)

{

MessageBox.Show(ex.Message.ToString());

}

}

另一种方法,我无法点击锚标记,也无法提升onclick事件。

private void ClickSelectAccount(IE ieInstance)

{

FrameCollection hframesSelAcct = ieInstance.Frames;

HTMLDocument document_sub_SelAcct = ((mshtml.HTMLDocument)(((WatiN.Core.Native.InternetExplorer.IEDocument)(((WatiN.Core.FrameCollection)(hframesSelAcct))[1].NativeDocument)).HtmlDocument));

foreach (HTMLAnchorElement anchorTagSelectAcct in document_sub_SelAcct.getElementsByTagName("a"))

{

if (anchorTagSelectAcct.innerText.Contains("Select Account"))

{

Thread.Sleep(2000);

//anchorTagSelectAcct.click();

anchorTagSelectAcct.FireEvent("onclick");

Thread.Sleep(10000);

ieInstance.WaitForComplete();

anchorTagSelectAcct.click();

Thread.Sleep(10000);

break;

}

}

}

可以请某人帮助我,第一次第二种方法工作正常但不是第二次。我对IE实例有疑问,因为我已经尝试了更多的睡眠时间,并且它能够进入循环但却无法点击链接。

先谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值