【问题标题】:How to select a label text in browser pop in selenium Python?如何在 selenium Python 的浏览器弹出窗口中选择标签文本?
【发布时间】:2015-03-17 07:58:27
【问题描述】:

谁能帮我在网络浏览器弹出窗口中选择“Logitech UE 4500”。

用于 HTML 的 PSB 已通过“driver.page_source”。

<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>

【问题讨论】:

  • 嗨 Anzel,在下面尝试过,但没有用
  • driver.find_element_by_xpath("//div[contains(@class, 'Logitech UE 4500')]").click()
  • driver.find_element_by_cssselector(".bluetooth-device-label > .Logitech UE 4500").click()
  • 'Logitech UE 4500'innerHTML/text 而不是 "class",因此你的尝试过不会完成你想要的。
  • @MuraliPerumal,如果这是一个弹出窗口,您需要确保在它可见时单击它。

标签: python html selenium


【解决方案1】:

尝试使用以下代码单击带有文本“Logitech UE 4500”的元素

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

注意:上述 xpath 将定位 div 元素,其类为“bluetooth-device-label”,并包含 innerHTML/text 为“Logitech UE 4500”。

【讨论】:

  • 不走运,得到错误:FAIL: Unhandled NoSuchElementException: Message: u'no such element\n (Session info: chrome=41.0.2258.2)\n (Driver info: chromedriver=2.13 (d94adb104175dc6837398cb4c45e99aeb2a38ba2 ),平台=Linux 3.10.18 x86_64)'
  • 大家好,它适用于:driver.find_element_by_xpath('//div[contains(@class,"bluetooth-device-label") ''and text()="' + 'Logitech UE 4500' + '"]').click()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多