【发布时间】:2018-03-11 13:05:21
【问题描述】:
有没有办法使用 selenium webdriver 识别驻留在电子邮件正文模板中的链接?
我试图自动化一个场景,在该场景中我将收到一封电子邮件,其中包含一个链接,可以点击以完成注册过程。
使用公共邮件服务器,我能够使用 Selenium 登录到基于 Web 的电子邮件提供商。我点击了收到的电子邮件,但网络驱动程序无法使用电子邮件正文模板中包含的 ID webelement 定位器识别链接。执行后出现以下错误:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"enrollmentURL"}
电子邮件链接的 HTML:
<a id="enrollmentURL" href="click1.clickrouter.com/…; style="font-family: &quot;arial&quot; , &quot;helvetica&quot; , sans-serif ; font-size: 16px ; line-height: 16px ; color: #fff ; text-decoration: none ; display: block" target="_other" rel="nofollow"><strong>GET&nbsp;STARTED</strong></a>
代码:
Generic.waitForElement(malinatoremailid,1,driver);
Generic.click(malinatoremailid,driver);
Generic.enterText(malinatoremailid,map.get(0).get("Email"),driver);
Generic.click(go,driver); Generic.waitForElement(email,2,driver);
Generic.click(email,driver);
【问题讨论】:
-
欢迎来到 Stack Overflow!请参阅:How do I do X? SO 的期望是,提出问题的用户不仅会进行研究以回答他们自己的问题,还会分享该研究、代码尝试和结果。这表明您已经花时间尝试帮助自己,它使我们免于重复明显的答案,最重要的是它可以帮助您获得更具体和相关的答案!另见:How to Ask
-
您使用的是哪个公共电子邮件服务器,您还可以发布所需区域的 HTML 以及您的 selenium 代码。
-
@Hac:Iam 使用 mailinator.com 邮件服务器和提到的细节:click1.clickrouter.com/…" style="font-family: "arial" , " ;helvetica”, sans-serif ; font-size: 16px ; line-height: 16px ; color: #fff ; text-decoration: none ; display: block" target="_other" rel="nofollow">GET  ;开始
-
Generic.waitForElement(malinatoremailid,1,driver); Generic.click(malinatoremailid,driver); Generic.enterText(malinatoremailid,map.get(0).get("Email"),driver); Generic.click(go,driver); Generic.waitForElement(email,2,driver); Generic.click(email,driver);
-
我想点击上面包含在电子邮件模板正文中的注册 URL id 定位器
标签: selenium selenium-webdriver