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

如何在selenium Python的浏览器弹出窗口中选择标签文本?,python,html,selenium,Python,Html,Selenium,有人可以帮助我如何选择“罗技UE 4500”在网络浏览器弹出窗口 用于HTML的PSB通过“driver.page_source”获得 罗技UE 4500 KKHAMPOX-MOBL2 尝试下面的代码单击文本为“Logitech UE 4500”的元素: driver.find_element_by_xpath("//div[@class='bluetooth-device-label' and contains(text(),'Logitech UE 4500')]").click() 注

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

用于HTML的PSB通过“driver.page_source”获得


罗技UE 4500
KKHAMPOX-MOBL2

尝试下面的代码单击文本为“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元素,并包含作为“Logitech UE 4500”的innerHTML/文本。

Hi Anzel,在下面尝试过,但没有成功。通过xpath(“div[contains(@class,'Logitech UE 4500')]”查找元素)。单击()驱动程序。通过cssselector查找元素(“.bluetooth设备标签>.Logitech UE 4500”)。单击()“Logitech UE 4500”是内部HTML/文本,而不是“类”“,因此您所尝试的不会达到您想要的效果。@MuraliPerumal,如果这是一个弹出窗口,您需要确保在它可见时单击它。如果运气不好,则会出现错误:FAIL:Unhandled NoSuchElementException:Message:u'No此类元素\n(会话信息:chrome=41.0.2258.2)\n(驱动程序信息:chromedriver=2.13(d94adb104175dc6837398cb4c45e99aeb2a38ba2),platform=Linux3.10.18x86_64)“您好,它使用的是:driver.find_element_by_xpath('//div[contains(@class,“bluetooth device label”)”和text()=“+”Logitech UE 4500'+'”)。单击()
driver.find_element_by_xpath("//div[@class='bluetooth-device-label' and contains(text(),'Logitech UE 4500')]").click()