无法获取 "input" 元素的值

Cannot get the value of an "input" element

我正在使用 Selenium 和 Java 编写测试。我需要在输入元素中获取文本:

<table class="boundaryFormAdd">
    <tbody>
       <tr>
          <td>
              <input id="id_name" type="text" style="margin-top: 5px">
          </td>
       </tr>
   </tbody>
</table>

但如您所见,它既没有 value 属性也没有任何内部文本。

我试过:

1) elementname.getAttribute("innerHTML")

2) elementname.getText()

请注意 input 标签没有像 </input> 那样的结束标签。他们里面没有任何东西。这些被称为空元素。所以 getText() ,getAttribute("innerHTML") - 不会 return 任何东西。

您可以使用 getAttribute(attrname) 方法访问 input 元素的其他属性。

要获取值,请尝试 driver.findElement(..).getAttribute("value")