当选择标签样式属性设置为 display: none; 时如何从下拉列表中检索值在 python 硒中

2024-02-14

我正在尝试废弃一个网站的下拉类别的所有组合。但是,选项的文本属性仅为空白。尽管在检查时,我可以看到每个选项都存在文本。

from selenium import webdriver
from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome()
driver.get('https://www.fiyo.nl/')

driver.find_element_by_xpath('//*[@id="select_device_chosen"]/a').click()
select = Select(driver.find_element_by_xpath('//*[@id="select-device"]'))
print ([o.text for o in select.options]) 

Output:

['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']

如果我收到文本,我想循环遍历所有值以获得其他下拉列表的不同组合。


The <select>标签有style属性设置为显示:无;因此您可以使用以下代码块来打印选项:

driver.find_element_by_xpath('//*[@id="select_device_chosen"]/a').click()
element = driver.find_element_by_xpath("//select[@id='select-device']")
driver.execute_script("arguments[0].removeAttribute('style')", element)
select = Select(driver.find_element_by_xpath("//*[@id='select-device']"))
print ([o.text for o in select.options])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当选择标签样式属性设置为 display: none; 时如何从下拉列表中检索值在 python 硒中 的相关文章

随机推荐