-1

I'm a bit new to selenium. I'm trying to select values from a drop-down menu using selenium in python, but for this website it does not seem to work.

Any ideas on how it can be done?

HTML code of dropdown:

<div id="dropdown-breakdown-select" class="drop-down drop-down--open">
   <div class="drop-down__selected drop-down__selected--open ">Geographical breakdown</div>
   <ul class="dropdown-list" tabindex="1" style="height: 246px; 
       display: block; overflow-y: hidden; outline: none;">
      <li style="font-weight: normal;">Geographical breakdown</li>
      <li style="font-weight: normal;">Rating</li>
      <li style="font-weight: normal;">Maturity</li>
      <li style="font-weight: normal;">Benchmark breakdown</li>
      <li style="font-weight: normal;">Risk currency</li>
      <li style="font-weight: normal;">Active currency risk</li>
      <li style="font-weight: normal;">Active duration risk</li>
   </ul>
</div>

Screenshot of dropdown:

enter image description here

Drop down from this page: Web link

yong
  • 13,357
  • 1
  • 16
  • 27
  • 2
    images of code are not acceptable. Your must edit the formatting by had if it does not copy over. *We* need to be able to *see* your code as text, and more importantly, *we* need to be able to copy and paste *your* code into our editors. Even poorly formatted code is more useable than an image. But every one of us should not need to perform this edit ourselves. Put in the effort, to help us help you. Anyway, if you use a code snippen (look for the <> symbol in the editor), then after you paste your code, there is a "prettier" link that will format the code properly! – SherylHohman Jan 31 '18 at 23:34

2 Answers2

0

Find element by css selector (#breakdown-select-wrapper .drop-down__selected) and click on it.

After that, iterate over lis (#dropdown-breakdown-select li) and find the one you are looking for by text.

Finally, click on it.

Nestor Yanchuk
  • 1,186
  • 8
  • 10
0

Because your drop down is a CSS dropdown, not native dropdown, you can't use Select class.

def choose_breakdown(option):

    // click to make option list visible
    driver
        .find_element_by_css_selector(
            "div#dropdown-breakdown-select > div.drop-down__selected"
        ).click()

    // choose option by given option text
    driver
        .find_element_by_xpath(
            "//div[@id='dropdown-breakdown-select']/ul/li[.='" + option + "']"
        ).click()
yong
  • 13,357
  • 1
  • 16
  • 27