0

I have a problem where I want to copy a URL from a message, where the URL is not clickable. I tried the following:

${email}=    Get Text    css:.msg-body
${url}=    Get Substring    ${email}    413    516

The code works, but the problem is that it may happen that the URL is placed in a different position, not between characters 413 and 516.

Is there a way to copy the URL based on a keyword, for example the start would be 'https'?

3
  • 1
    I can imagine regexp would be an option.
    – pavelsaman
    Sep 21, 2020 at 11:03
  • 1
    you can use javascript executor to highlight the element Nov 6, 2020 at 6:57
  • Please rename the question highlighting rather means adding a border or backgroud to the text. What you are looking for is getting a substring of a text. Jan 2, 2021 at 20:38

1 Answer 1

1

As @pavelsaman say, regex would be suitable.
In it's simplest form https.*
${url}= Get Regexp Matches ${email} https://.*

. stands for match of any type of character.
* stand for zero or more of the preceding character.

This is a very greedy expression and will match from https to the end since it will match one or zero of any character after https.

If possible it is better to make the expression more strict by adding some end expression as well.

I think this page is good for regex elaboration.
https://regex101.com/

And please notice that in Robot Framework you might need to escape backslashes \ with another backslash \.
BuiltIn - Pattern Matching

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.