1

So I am trying to run the following code to select an option from a drop-down toolbar:

## Drop-down menu
time.sleep(5) # wait for element to load in page otherwise selenium won't be able to find it
element_dropdown = driver.find_element("id","conference-dropdowns")
element_dropdown.click()

# Select visible text
time.sleep(5)
select = Select(element_dropdown)
select.select_by_visible_text("Bulk Upload")

But then I get the following error:

UnexpectedTagNameException: Message: Select only works on <select> elements, not on <label>

How do I resolve this issue? Why am I getting this error? See structure below. Thanks so much in advance. enter image description here

mexicanRmy
  • 69
  • 7
  • What are you trying to achieve? Testing, or you want to scrape the data? If scraping, post the full url. – Barry the Platipus Jul 21 '22 at 22:19
  • @platipus_on_fire_333 I'm trying to create a program that will login to a site, navigate through a few toolbars and upload a CSV file after clicking "Bulk Upload". – mexicanRmy Jul 21 '22 at 22:22
  • If your end goal is to upload a file, you can achieve this with requests - you can login, then upload that file. – Barry the Platipus Jul 21 '22 at 22:24
  • @platipus_on_fire_333 Oh cool! Could you send some resources on how to achieve this? I'm very new to Selenium, requests, etc. – mexicanRmy Jul 22 '22 at 18:14
  • https://stackoverflow.com/questions/11892729/how-to-log-in-to-a-website-using-pythons-requests-module and https://stackoverflow.com/questions/22567306/how-to-upload-file-with-python-requests – Barry the Platipus Jul 22 '22 at 18:16

2 Answers2

1

The Exception says everything: you can use Select class only with <select> object. Simply try to

  • click() on button to expand drop-down menu
  • wait for required option to be clickable
  • click() on option
JaSON
  • 4,843
  • 2
  • 8
  • 15
1

The desired element isn't within any tag, but they are within <label> tag.

Bulk Upload

So you won't be able to use Select() class.


Solution

The click element with text as Bulk Upload you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategy:

  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[@class='dropdown-submenu']//label[@class='submenu' and contains(., 'Bulk Upload')]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352