Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium通过遍历父节点来单击按钮_Python_Selenium_Button_Xpath - Fatal编程技术网

Python Selenium通过遍历父节点来单击按钮

Python Selenium通过遍历父节点来单击按钮,python,selenium,button,xpath,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="devi

需要在下面的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>

关于
元素[0]呢。通过xpath(“…”)查找元素(“…”)
@eLRull:谢谢你指出,我在查找元素时不需要list.np,它有效吗?parent=element。通过xpath(“…”)查找元素dev\u id=parent。get\u属性(“id”)-->获取了我的id。我使用parent元素和css访问删除按钮。无法找到具有dev_id的构造xpath
parent = element.find_element_by_xpath("..").text()