【发布时间】: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>
【问题讨论】:
-
我不认为这是重复的......我没有首先定位元素