2

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'
2
  • How are you initializing webelement variable? Commented Mar 17, 2016 at 5:31
  • I am find element by xpath and storing it popupSelect variable in MyCode.py Commented Mar 17, 2016 at 5:38

1 Answer 1

12

find_elements_by_xpath returns list of WebElements.

It should be find_element_by_xpath. Note the s in find_element.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for answering
Hi @M Talha Afzal I have the same problem but your suggestion doen't work. Can you help me on this issue? stackoverflow.com/questions/49362476/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.