Selenium遍历父节点单击按钮

时间:2017-03-07 01:26:44

标签: python selenium button xpath

需要在以下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>&nbsp;
            <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()

0 个答案:

没有答案