[英]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.