Capture input's label text with Selenium2Library

1.8k Views Asked by At

I am trying to capture the label of the Textbox using robot framework and use the label text as variable. Is there any way to do that? The related html code is given below. enter image description here

<div class="col-xs-6">

                    <div class="well" style="background-color:white;">

<div class="form-group">

    <label for="name_of_phenotype_entering">Please enter your name separated by comma (e.g Last, First)</label>

    <input class="form-control" id="name_of_phenotype_entering" name="name_of_phenotype_entering" type="text" value="">

</div>

Thanks for your support.

1

There are 1 best solutions below

1
On BEST ANSWER

You can use the following XPATH to locate your <label> element: //label[@for="name_of_phenotype_entering"]

At this point you can use the Get Text keyword to retrieve the element's text in a variable, like this:

${label_text}=    Get Text    xpath=//label[@for="name_of_phenotype_entering"]