需要在以下HTML中练习按钮(编辑/删除)。所有设备之间的唯一关系是"设备名称"。因此,定位目标设备是直的 -
cmd = "//div[@class='device-name' and text()='%s']" % (devicename)
element = brHandle.find_elements_by_xpath(cmd)
HTML -
<div class="device" id="device-1">..</div>
<div class="device" id="device-2">..</div>
<div class="device-form-factor desktop">
<div class="device-platform unknown"></div>
<div class="device-status">
....
</div>
</div>
<div class="device-name">auto-generated</div>
<div class="buttons">
<div class="button edit" href="#">Edit</div>
<div class="button delete" href="#">Delete</div>
</div>
</div>
<div class="device" id="device-3">..</div>
...
要访问父母,然后按钮,我尝试了以下 - 但没有成功。我期待获取device-id,然后形成我的xpath来编辑/删除按钮。请建议 -
parent = element.find_element_by_xpath("..").text()