1

I am writing an automation test script using Robot Framework & Selenium2Library for testing our web application ( in .txt format ).

One of my test cases involves to select few lines of text from web page, following with this text selection, some text formatting options will render in page to modify the style of that particular selected text ( Please refer the following image ).

Text selection

enter image description here

1) Is there any specific keyword in Robot Framework to select few text or few lines of text from a webpage ?

Here is the HTML code of the particular section :

     <div>
         I am writing an automation test script using Robot Framework & Selenium2Library for testing our web application(in '.txt' format).
     </div>

Along with that, can I store the selected text field into a variable ?

2) If I Select bold from the text formattings option, html code will change like this :

    <div>
         I am writing an <b> automation test script </b> using Robot Framework & Selenium2Library for testing our web application(in '.txt' format).
    </div>

Is there any method in Robot Framework to get the text field inside a particluar html tag ?

Here, Can I store the text field in between html <b> tag? [ But id's willn't be there ! ]

2 Answers 2

2

This can be solved as well by using:

*** Setting ***
Library     Selenium2Library
Library     String

*** Test Cases ***
Get subselection
    ${string}=    Get Text    xpath=/html/div
    ${substring}=    Get Substring  ${string}   25  35
0

You can do it via Selenium2Library.Execute JavaScript.

  1. <html>
    <div>I am writing an automation test script using Robot Framework & Selenium2Library for testing our web application(in '.txt' format).</div>
    </html>
    

    Following code selects "automation test script"

    | Execute Javasctipt | var n=document.getElementsByTagName('div')[0].firstChild; | var r = document.createRange(); | r.setStart(n, 16); | r.setEnd(n, 38); | var s = window.getSelection(); | s.removeAllRanges(); | s.addRange(r); | return s.toString(); |
    

  1. <html>
    <div>I am writing an <b> automation test script </b> using Robot Framework & Selenium2Library for testing our web application(in '.txt' format).</div>
    </html>
    

    Following code selects "writing an automation"

    | Execute Javasctipt | var e=document.getElementsByTagName('div')[0]; | st = e.childNodes[0]; | en = e.childNodes[1].firstChild; | var r = document.createRange(); | r.setStart(st, 5); | r.setEnd(en, 11); | var s = window.getSelection(); | s.removeAllRanges(); | s.addRange(r); | return s.toString(); |
    
0

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.