I want to use selenium and python to crawl this site : https://ntrl.ntis.gov/NTRL
However when i want to change the year of drop-down list, it can't work.
Here are its HTML:
<div id="advSearchForm:FromYear" class="ui-selectonemenu ui-widget ui-state-default ui-corner-all" style="min-width: 63px;">
<div class="ui-helper-hidden-accessible">
<input id="advSearchForm:FromYear_focus" name="advSearchForm:FromYear_focus" type="text" autocomplete="off" role="combobox" aria-haspopup="true" aria-expanded="false" readonly="readonly" aria-autocomplete="list" aria-owns="advSearchForm:FromYear_items" aria-activedescendant="advSearchForm:FromYear_0" aria-describedby="advSearchForm:FromYear_0" aria-disabled="false">
</div>
<div class="ui-helper-hidden-accessible">
<select id="advSearchForm:FromYear_input" name="advSearchForm:FromYear_input" tabindex="-1">
<option value="*" selected="selected"><1900</option>
<option value="1900">1900</option>
<option value="1901">1901</option>
<option value="1902">1902</option>
<option value="1903">1903</option>
</select>
</div>
<label id="advSearchForm:FromYear_label" class="ui-selectonemenu-label ui-inputfield ui-corner-all"><1900</label>
<div class="ui-selectonemenu-trigger ui-state-default ui-corner-right">
<span class="ui-icon ui-icon-triangle-1-s ui-c"/>
</div>
</div>
Here are my code:
select = Select(driver.find_element_by_xpath(".//div[@id='advSearchForm:FromYear']/div[2]/select"))
select.select_by_value("1902")
But it get exception:
Element is not currently visible and may not be manipulated
I tried to use js script:
driver.execute_script("document.getElementById('advSearchForm:FromYear_input').options[2].selected = 'true'")
But it also don't work,I test that select.select_by_value(xxx)
can be used on other drop-down list, so it may be the trouble of <div class="ui-helper-hidden-accessible">
, so how can i deal with it?