【问题标题】:Unable click on the link button of email template using selenium webdriver使用 selenium webdriver 无法单击电子邮件模板的链接按钮
【发布时间】: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: "arial" , "helvetica" , sans-serif ; font-size: 16px ; line-height: 16px ; color: #fff ; text-decoration: none ; display: block" target="_other" rel="nofollow"><strong>GET STARTED</strong></a>

代码:

Generic.waitForElement(malinatoremailid,1,driver); 
Generic.click(malinatoremailid,driver); 
Generic.enterText(malinatoremailid,map.get(0).get("Email"),d‌​river); 
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" , &quot ;helvetica”, sans-serif ; font-size: 16px ; line-height: 16px ; color: #fff ; text-decoration: none ; display: block" target="_other" rel="nofollow">GET&nbsp ;开始
  • 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


【解决方案1】:

我能够查看来自 mailinator https://www.mailinator.com/v2/inbox.jsp?zone=public&query=HeadyPie#/#msgpane 的示例电子邮件之一

如果您进一步查看 html,您会看到电子邮件正文包含在 iframe 下。因此,点击电子邮件后,您必须先切换到该 iframe,然后再点击链接:

// Click on the email

// Now switch to the email body iframe:
driver.switchTo().frame("msg_body");

// Click on the email link 

// If you need to go back to the menu, don't forget to switch back:
driver.switchTo().defaultContent();

【讨论】:

  • 耶!很高兴它奏效了。也感谢您接受我的回答。
  • 谢谢你!我花了 1 个小时,可以理解是什么问题。
猜你喜欢
  • 2019-07-10
  • 2021-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-17
  • 2017-01-17
  • 2021-11-09
相关资源
最近更新 更多