我想识别这个元素“带有文本响应的问题”,它没有唯一的 ID、类或属性。
我已经尝试过这个:
@FindBy(css = "body")
谁能帮我找到这个吗?
这是 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>
最佳答案
您可以使用 xpath 中的文本找到该元素。
你可以这样做:
WebElement element = driver.findElement(By.xpath("//label[contains(text(),'Question With Text Response')]"));
关于java - 我怎样才能识别这个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60666269/