1
我試圖訪問使用硒HTML,看起來像這樣一個下拉菜單:下拉菜單中硒 - Python 3中
<span class="k-pager-sizes k-label">
<span title="" class="k-widget k-dropdown k-header" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="" aria-disabled="false" aria-readonly="false" aria-busy="false" aria-activedescendant="8e90d557-7e8d-4c5c-b906-202fd78c6d0a"><span unselectable="on" class="k-dropdown-wrap k-state-default">
<span unselectable="on" class="k-input">20</span><span unselectable="on" class="k-select">
<span unselectable="on" class="k-icon k-i-arrow-s">select</span>
</span>
</span>
<select data-role="dropdownlist" style="display: none;">
<option value="10">10</option><option value="15">15</option>
<option value="20">20</option><option value="50">50</option>
<option value="100">100</option>
</select>
<span>items per page</span>
我曾嘗試沒有成功如下:
try:
driver = webdriver.Chrome('/Users/opusandcaymus/Election/chromedriver')
driver.get('http://mcad-tx.org/Property-Search-Result?searchtext=Maple%20Branch')
#dropdown=driver.find_element_by_xpath('//*[@id="grid"]/div[3]/span[2]/span/select')
#select = Select(dropdown)
dropdown = driver.find_elements_by_tag_name("option")
for row in dropdown:
print(row.value)
driver.close()
except:
print("error")
driver.close()
raise
不任何人都知道如何通過值來找到選項?每次打開頁面時,我都想選擇100。
完美無瑕。謝謝你的答案。我仍然在學習如何在Python中使用Selenium中的JavaScript。很有幫助。 –