0

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.set_page_load_timeout(60)
    driver.get("https://www.finance.yahoo.com")
    driver.maximize_window()
    driver.implicitly_wait(20)
    driver.get_screenshot_as_file("yahoo_finance.png")
    driver.find_element_by_name("yfin-usr-qry").send_keys("IBM")
    driver.find_element_by_id("search-button").click()
    driver.find_element_by_css_selector("li.IbBox:nth-child(3) > a:nth-child(1)").click()
    driver.find_element_by_css_selector(".indicatorsBtn\:h_C\(\$c-fuji-blue-1-a\)").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)
    print(element.text) 


   select_box = Select(element)
   select_box.select_by_value('Exponential')
`
  • Could you share the error and trim the code to only the part of interested (e.g., the driver.get is irrelevant to the problem)? – João Farias Sep 20 at 5:50
  • I added the error and slimmed down the code. The real issue is that I cannot get the drop down lists to work. – Chad Leonard Sep 20 at 13:34
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.