0

How to spot out the link and click the link from email body.

${FIELD NAME}=    ImapLibrary.Get Links From Email    ${latest}
${mailbody}=    ImapLibrary.Get Email Body    ${latest}
${HTML}=    ImapLibrary.Open Link From Mail    ${latest}

But when I give "Get Email Body", I'm able to get total content in email body. How to spot out the links from there and how to click from there?

Laurent Bristiel
  • 6,819
  • 34
  • 52
karthika s
  • 11
  • 2
  • 5

1 Answers1

0

To find links you need to use regexps. For example this Stackoverflow question answers how to find urls in text: Regex to find urls in string in Python

It looks like this in Robot Framework:

*** Settings ***
Library           re

*** Variables ***
${mailbody}   this is mail body http://www.stackoverflow.com/ foobar https://stackoverflow.com/questions/31288261/how-to-click-the-link-in-email-body-and-how-to-spot-out-the-link-using-robot-fra

*** Settings ***
Library           re

*** Variables ***
${mailbody}   this is mail body http://www.stackoverflow.com/ foobar https://stackoverflow.com/questions/31288261/how-to-click-the-link-in-email-body-and-how-to-spot-out-the-link-using-robot-fra
${url regexp}    http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+

*** Test Cases ***
Get Urls
    @{lines}=    re.findall    ${url regexp}    ${mailbody}     
    Log Many    @{lines}

You cannot really click the links, instead you should use Selenium2Library to open them in browser.

Community
  • 1
  • 1
Pekka
  • 2,175
  • 15
  • 20
  • thank u so much.. i m able to get all links . Now how to point out the link. if it displays 10 links . open browser firefox Go to @{lines}[9]. can i give like this . to go via that link – karthika s Jul 09 '15 at 05:55
  • You can open them in browser with Selenium2Library: https://github.com/rtomac/robotframework-selenium2library – Pekka Jul 09 '15 at 05:59
  • I can never remember correct syntax for Selenium2Library so I have this link in my browser toolbar: http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html. Correct command is: "Open Browser @{lines}[9] Firefox – Pekka Jul 09 '15 at 06:06
  • can log many be stored in a variable like this ${values}= Log Many @{lines} – karthika s Jul 09 '15 at 06:27
  • I don't think so. I don't understand what you are trying to do, please open a new question. – Pekka Jul 09 '15 at 06:42
  • when i give Open Browser @{lines}[9] it gives error Variable '@{lines}[9]' not found – karthika s Jul 09 '15 at 06:48
  • I m getting list of links using logmany function.How to open 8 th link in a new browser. – karthika s Jul 09 '15 at 06:52
  • @{lines} is a Python list and the first item is @{lines}[0] – Pekka Jul 09 '15 at 07:15
  • Open Browser @{lines}[9] it works.. thank u so much – karthika s Jul 09 '15 at 09:13