Selenium not allowing to choose from dynamic drop down list values

  • I'm using Firefox and Selenium with Python 3.7.

    What I'm try to do is: from the Yahoo Finance page search for IBM in the search box and go to that page and select "chart." This brings up the chart option for technical analysis. Then select "Indicators" and choose "Moving Average". From here I am able to fill in the "period" and "offset" text boxes but I cannot select from the "field" and "type" drop down lists.

    I have checked some of the answers for similar problems here at stackexchange but none of the solutions worked. For one, when I inspect the drop down list it does not show all the options. Only the one that is selected. The drop down list must be dynamic(?). I can get the code to return the value that is the default value ("Simple" for "type"), the one that is selected, but I cannot change it.

    I tried using the Select command but that requires a select tag and the tag here is span. I also tried ActionChains but with no success. This is very easy to setup and try. The code I'm running is below. What I would like to know is how to select from the "Field" and "Type" drop down lists?

    error: selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on elements, not on

        driver.find_element_by_css_selector("li.IbBox:nth-child(3) > a:nth-child(1)").click()
        driver.find_element_by_css_selector("ul.Fz\(s\):nth-child(2) > li:nth-child(1) > button:nth-child(1)").click()
        driver.find_element_by_css_selector("tr.Bdcl\(c\):nth-child(1) > td:nth-child(2) > input:nth-child(1)").clear()
        driver.find_element_by_css_selector("tr.Bdcl\(c\):nth-child(1) > td:nth-child(2) > input:nth-child(1)").send_keys(9)
        ddown = "tr.Bdcl\(c\):nth-child(3) > td:nth-child(2) > span:nth-child(1) > div:nth-child(1)"
        element = driver.find_element_by_css_selector(ddown)
       select_box = Select(element)

  • The element ddown = "tr.Bdcl\(c\):nth-child(3) > td:nth-child(2) > span:nth-child(1) > div:nth-child(1)" that you are considering is not Select instead Span

       <span data-test="Type-selected" class="O(n):f O(n):h P(0) M(0) C($c-fuji-blue-1-b) Fz(s)">Exponential</span>

    Here you may consider finding each element and clicking individually.

Suggested Topics

  • 2
  • 3
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2