Search code examples
pythonseleniumselectdropdown

Selenium Python coding to select dropdown : getting error SeleAttributeError: 'list' object has no attribute 'tag_name'


Code:

from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome('./chromedriver')
driver.get("http://www.tizag.com/htmlT/htmlselect.php")
time.sleep(5)
element= driver.find_elements_by_xpath('/html/body/table[3]/tbody/tr[1]/td[2]/table/tbody/tr/td/div[4]/select')
sel= Select(element)
sel.select_by_value("CO")
time.sleep(5)
print('Done')

Error message if webelement.tag_name.lower() != "select": AttributeError: 'list' object has no attribute 'tag_name'


Solution

  • please find below solution to resolve your problem. Xpath is wrong in your solution

    from selenium import webdriver
    from selenium.webdriver.support.select import Select
    from selenium.webdriver.common.keys import Keys
    import time
    driver = webdriver.Chrome('./chromedriver')
    driver.get("http://www.tizag.com/htmlT/htmlselect.php")
    time.sleep(5)
    
    select =Select(driver.find_element_by_xpath("//div[4]//select[1]"))
    select.select_by_index(1)
    
    
    print('Done')