3

I'm trying to click on multiple dropdown lists on a page but I keep getting an error saying that my list object has no attribute tag_name'.

My code

def click_follow_buttons(driver):
    selects = Select(driver.find_elements_by_class_name("jBa"))#jBa
    print selects
    for select in selects:
        select.select_by_index(0)
        driver.find_element_by_class_name("bA").click()

My traceback

Traceback (most recent call last):
  File "google_follow.py", line 50, in <module>
    if click_follow_buttons(driver) == False:
  File "google_follow.py", line 18, in click_follow_buttons
    selects = Select(driver.find_elements_by_class_name("jBa"))#jBa
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/support/select.py", line 35, in __init__
    if webelement.tag_name.lower() != "select":
AttributeError: 'list' object has no attribute 'tag_name'

The Html dropdown

<div class="jBa XG">
<div class="ny dl d-k-l" jslog="7128; track:impression">

2 Answers 2

1

First of all, you are using the find_elements_by_class_name() method that would return you a list of web elements matching a class name and not a single element.

But, even if you would use find_element_by_class_name() instead, you'll get a different error since this is a div element matching the class name and not a select element.

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

2 Comments

@alexce I was first =P
@drets well, there is a difference in the answers though :)
0

You need to pass to constructor of Select class web element which has select tag name: https://selenium.googlecode.com/git/docs/api/py/webdriver_support/selenium.webdriver.support.select.html

Constructor. A check is made that the given element is, indeed, a SELECT tag. If it is not, then an UnexpectedTagNameException is thrown.

Comments

Your Answer

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