【问题标题】:Python Selenium - Locating text Inside Input Id PropertyPython Selenium - 在输入 ID 属性内定位文本
【发布时间】:2019-04-03 23:34:09
【问题描述】:

试图定位一个似乎实际上具有输入元素动态属性的输入元素。此输入位于 td 内,并在网页上显示成功或失败,并在文本完成代码旁边。我试过 xpath 和 id 来查找输入元素,但我得到“无法找到元素”一旦我完成了上面的第一步,然后我想提取 value 字段中的内容,这实际上是旁边网页上显示的文本完成代码。例如

完成代码成功

我的代码 -

completion_code = driver.find_element(By.XPATH, '//*[@id="code"]')
print(completion_code.text)

html

<tr>
   <td id="label.code" class="label" type="string" choice="0" height="23px" nowrap="true">
   <label onclick="" for="code" dir="ltr" class="  control-label"><span id="status." mandatory="false" oclass="" aria-label="" class=" required-marker"></span>
   <span class="label-text" data-html="false">Completion code</span>
   </label>
</td>
   <td style="background-color:PaleGreen;width:100%;;" nowrap="true">
   <input autocomplete="off" autocorrect="off" readonly="readonly" name="code" id="code" value="Success" onkeyup="" onchange="onChange('code');" size="" style="border:0px;background:transparent" maxlength="" type="text">
   </td>
</tr>

【问题讨论】:

标签: python selenium input


【解决方案1】:

好吧,事实证明我认为等待不是一个因素,添加了这一点,然后从输入框中获取了显示所需结果的值

 transform_history = driver.find_element_by_name("code")     
 print(transform_history.get_attribute('value'))

【讨论】:

  • String dataID = transform_history.GetAttribute('id'); 是您从问题中寻找的内容。 @anfield 我想。
猜你喜欢
  • 2020-05-28
  • 2013-09-04
  • 1970-01-01
  • 1970-01-01
  • 2023-04-04
  • 1970-01-01
  • 1970-01-01
  • 2019-08-19
  • 1970-01-01
相关资源
最近更新 更多