How can I identify this element

sap :

I want to identify this element "Question With Text Response" which has no unique id, class or attribute.

I have tried this:

@FindBy(css = "body")

Can anyone please help me to locate this?

Here is the HTML:

<tr valign="top" xpath="1">
   <td width="80%">
      <div id="div-4fd242f670a4bc4e0170beb543d72c66" class="wordwrap" style="padding-left:20px;padding-top:3px;">
         <label for="name" class="portlet-form-field-label">
         2.
         Question With Text Response<span style="color:red;">*</span>
         </label>
         <br>
         <textarea id="4fd242f670a4bc4e0170beb543d72c66" name="answers[4fd242f670a4bc4e0170beb543d72c66]" class="portlet-form-input-field answers[4fd242f670a4bc4e0170beb543d72c66]  comment" style="width:90%;" onkeydown="return imposeMaxLength(event, this, 3999);" onblur="return imposeMaxLength(event, this, 3999);" rows="7"></textarea>    				
      </div>
   </td>
</tr>

NarendraR :

As per your HTML structure the label and textarea are sibling tags So to locate textarea based on label text,

Use below xpath:

@FindBy(xpath = "//label[contains(.,'Question With Text Response')]/following::textarea")

Explanation:

//label[contains(.,'Question With Text Response')] - find label which contains text 'Question With Text Response'

/following::textarea or /following-sibling::textarea - locate the text are which follows the label

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=237763&siteId=1
Recommended