如何在Selenium Python中选择浏览器弹出窗口中的标签文本?

2024-05-08 23:08:14 发布

您现在位置:Python中文网/ 问答频道 /正文

有人能帮助我如何选择“罗技UE 4500”在网页浏览器弹出窗口。在

用于HTML的PSB已通过“driver.page_源". 在

<list id="bluetooth-paired-devices-list" role="list" tabindex="0">
<div class="spacer" style="height: 0px;">
</div>
<div role="listitem" class="deletable-item bluetooth-device"     paired="paired">
<div>
<div class="bluetooth-device-label">Logitech UE 4500</div>
</div>
<button class="raw-button row-delete-button custom-appearance"     tabindex="-1" title="Delete this item">
</button>
</div>
<div class="spacer" style="height: 0px;">
</div>
</list>
<div role="listitem" class="deletable-item bluetooth-device">
<div><div class="bluetooth-device-label">KKHAMPOX-MOBL2</div>

Tags: divstyledevicebuttonitemlistclassrole
1条回答
网友
1楼 · 发布于 2024-05-08 23:08:14

尝试以下代码单击文本为“Logitech UE 4500”的元素。

driver.find_element_by_xpath("//div[@class='bluetooth-device-label' and contains(text(),'Logitech UE 4500')]").click()

注意:上面的xpath将找到类为“bluetooth device label”的div元素,并将innerHTML/text包含为“Logitech UE 4500”。

相关问题 更多 >