1

Is there a way to identify the link residing in an email body template using selenium webdriver?

I was trying to automate a scenario where I will receive an email with a body having a link to click to complete the registration process.

Using a public mail server I was able to login into a web-based email provider with Selenium. I clicked on the email which I received but web driver was not able to identify the link using ID webelement locator enclosed in the email body template. After execution I am ending up with the following error:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"enrollmentURL"}

HTML of email link:

<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>

Code:

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);
4
  • Which public email server are you using and can you also post the HTML of the required areas, and your selenium code. Commented Oct 2, 2017 at 23:44
  • @Hac:Iam using mailinator.com mail server and the details mentioned:<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> Commented Oct 3, 2017 at 15:30
  • 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); Commented Oct 3, 2017 at 15:35
  • I want to click on the above enorllment URL id locator enclosed in an email template body that's it Commented Oct 3, 2017 at 15:37

1 Answer 1

2

I was able to check out one of the sample emails from mailinator https://www.mailinator.com/v2/inbox.jsp?zone=public&query=HeadyPie#/#msgpane

If you look further up in the html, you will see that the email body is contained under an iframe. So after clicking on the email, you will first have to switch to that iframe before clicking the link:

// 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();
Sign up to request clarification or add additional context in comments.

2 Comments

Yay! Glad it worked. And thanks for accepting my answer too.
Thank u! I spent 1 hour, could understand what's the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.