我正在编写一个自动创建帐户的小应用程序。我使用网站http://temp-mail.org来生成电子邮件地址。
目前,在我的代码中,日志显示已点击链接,但事实并非如此。我的第一个问题是在注册时有3封电子邮件发送,并产生以下HTML代码。问题都没有ID,唯一的区别是" title-subject"。
<tbody>
<tr>
<td>"PlayStation Network" <sony@email.sonyentertainmentnetwork.com></td>
<td>
<a href="http://temp-mail.org/en/view/e9527b19d5db504182428bac583977fe"
class="title-subject">Controleer je account.</a>
</td>
<td>...</td>
<td class="text-center">
<a href="http://temp-mail.org/en/view/e9527b19d5db504182428bac583977fe"
class="link">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</td>
</tr>
<tr>
<td>"PlayStation Network" <Sony@email.sonyentertainmentnetwork.com></td>
<td>
<a href="http://temp-mail.org/en/view/d3b3a892daeb5c99d85f4c5999242664"
class="title-subject">Je gebruikersnaam is bijg</a>
</td>
<td>...</td>
<td class="text-center">
<a href="http://temp-mail.org/en/view/d3b3a892daeb5c99d85f4c5999242664"
class="link">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</td>
</tr>
</tbody>
在电子邮件中,有一个必须单击的链接,并且该链接具有以下HTML
<td align="center"
width="150"
height="40"
bgcolor="#3071a3"
style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #ffffff; display: block;">
<a href="https://account.sonyentertainmentnetwork.com/liquid/cam/account/email/validate-email.action?service-entity=np&token=YTVhOTc4ZjItMDI230F3cH9ehcugYxy%2BC9YWHgnQ8l8lh2v%2F943yVVYQWQS4XUlJNMHt0cUlVMpBGAdc7TcwraMoF8K6CQr5QsfaDknPNIgmmWUGyM%2FcEF67%2BHk%3D&request_locale=nl_NL"
style="color: #ffffff; font-size:16px; font-weight: bold; font-family: Arial, Helvetica, sans-serif; font-size:18px; text-decoration: none; line-height:40px; width:100%; display:inline-block">Nu bevestigen</a>
</td>
现在我尝试使用以下代码:
void DoConfirmation()
{
Log("Verifying Email...");
NavigateAndWait("http://temp-mail.org");
bool RecievedConfEmail = false;
for (;;)
{
if (!RecievedConfEmail)
{
HtmlElementCollection links = _WebDocument.GetElementsByTagName("A");
foreach (HtmlElement link in links)
{
if (link.InnerText.Equals("account"))
link.InvokeMember("Click");
Log("I clicked that email you asked");
RecievedConfEmail = true;
break;
}
}
else
{
HtmlElementCollection links = _WebDocument.GetElementsByTagName("A");
foreach (HtmlElement link in links)
{
if (link.InnerText.Equals("Bevestigen"))
link.InvokeMember("Click");
Log("I clicked IN the Email #2");
return;
}
}
Wait(25);
}
}
所以我尝试通过搜索单词&#34; account&#34;来抓住第一个正确的电子邮件。在第二个单词中有&#34; bevestigen&#34;。即使日志显示链接已被点击,但事实并非如此。
有人可以通过更聪明,更健壮的方式帮助我抓住正确的电子邮件并点击链接吗?
答案 0 :(得分:0)
这是因为即使InnerText
不等于(account
或Bevstigen
),您也会记录。看看你的if块。您也退出foreach
,因此只查看单个链接。在两个{}
语句后使用if
。例如:
foreach (HtmlElement link in links)
{
if (link.InnerText.Equals("account"))
{
link.InvokeMember("Click");
Log("I clicked that email you asked");
RecievedConfEmail = true;
break;
}
}
foreach (HtmlElement link in links)
{
if (link.InnerText.Equals("Bevestigen"))
{
link.InvokeMember("Click");
Log("I clicked IN the Email #2");
return;
}
}