M Talha Afzal
M Talha Afzal

Reputation: 241

Python Selenium Webdriver: AttributeError 'list' object has no attribute 'tag_name'

I am having a trouble with the select element when I try to run my code it gives me an error

AttributeError 'list' object has no attribute 'tag_name'

like I don't have any select element. Is it because it is not focusing on popup? What am I doing wrong?

enter image description here

MyCode.py

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

browser = webdriver.Firefox()
browser.get("http://www.punjnud.com/PageList.aspx?BookID=14050&BookTitle=Ali%20Zaryoun%20Ki%20Ghazalein")

popupSelect=Select(browser.find_elements_by_xpath("(//select[@class='custom-dropdown selectdrop'])[1]"))

popupSelect.select_by_value("1")

browser.find_elements_by_class_name("btn btn-success").click()

Error in select.py:

if webelement.tag_name.lower() != "select":
    raise UnexpectedTagNameException("Select only works on <select> elements, not on <%s>" %webelement.tag_name)

Exception:

AttributeError: 'list' object has no attribute 'tag_name'

Upvotes: 2

Views: 28492

Answers (1)

Guy
Guy

Reputation: 51009

find_elements_by_xpath returns list of WebElements.

It should be find_element_by_xpath. Note the s in find_element.

Upvotes: 12

Related Questions