繁体   English   中英

使用 Selenium Web 驱动程序和 Python 获取所选选项时出错

[英]Error by getting selected option using Selenium Web Driver with Python

为了 output 我已经选择的选项我编码:

Select(driver.find_elements(By.XPATH,'path_to_select/select/option'))
selected_option = select.first_selected_option
print(selected_option)

错误信息:

引发 UnexpectedTagNameException(selenium.common.exceptions.UnexpectedTagNameException:消息:Select 仅适用于元素,不适用于

因为您正在选择元素列表。 因此,您可以使用driver.find_element()而不是 driver.find_elements() 来 select 单个元素。

select = Select(driver.find_element(By.XPATH,'path_to_select/select/option'))
selected_option = select.first_selected_option
print(selected_option)

driver.find_elements返回WebElements列表

应该是driver.find_element 注意find_element中的s

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM