不能 select 选项与 Python Selenium (javascript?)

Cannot select options with Python Selenium (javascript?)

我正在尝试自动执行此页面上的下载过程:https://cdr.ffiec.gov/public/PWS/DownloadBulkData.aspx

特别是,我希望能够 select "Reporting Period End Date" 下拉列表中的任何选项。

<select name="ctl00$MainContentHolder$DatesDropDownList" onchange="javascript:setTimeout(&#39;__doPostBack(\&#39;ctl00$MainContentHolder$DatesDropDownList\&#39;,\&#39;\&#39;)&#39;, 0)" id="DatesDropDownList" class="valuelabel">
        <option selected="selected" value="81">12/31/2014</option>
        <option value="80">09/30/2014</option>
        <option value="79">06/30/2014</option>
        <option value="78">03/31/2014</option>
        <option value="76">12/31/2013</option>
                ...
</select>

我在 Selenium 中尝试了以下方法,但它 returns 是一个空列表:

url = 'https://cdr.ffiec.gov/public/PWS/DownloadBulkData.aspx'
driver = webdriver.Firefox()
driver.get(url)
date_field = driver.find_element_by_id("DatesDropDownList")
Select(date_field).options

我认为问题出在 select 中的 javascript。正确的做法是什么?

您的页面功能需要您 select 来自第一个列表框的值 :)

因此 select 来自 "Available Products" 的值,然后日期下拉列表被填充。

browser = webdriver.Firefox()
browser.get('https://cdr.ffiec.gov/public/PWS/DownloadBulkData.aspx')

list1 = Select(browser.find_element_by_id("ListBox1"))
list1.select_by_visible_text("Call Reports -- Single Period")

date_field = Select(browser.find_element_by_id("DatesDropDownList"))
date_field.select_by_visible_text("03/31/2014")