我正在嘗試從此處訪問的下拉串列中選擇佛羅里達州的一個縣,但到目前為止我嘗試過的任何方法都無法找到頁面中的任何元素或與之互動。通常,我收到錯誤:
NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//select[@id='form:county_input']//option[value='24']"}
(Session info: chrome=100.0.4896.60)
這似乎是相關的片段:
<div id="form:county" class="ui-selectonemenu ui-widget ui-state-default ui-corner-all" style="width:500px;" role="combobox" aria-haspopup="true" aria-expanded="false" aria-owns="form:county_items">
<div class="ui-helper-hidden-accessible">
<input id="form:county_focus" name="form:county_focus" type="text" autocomplete="off" aria-expanded="false" aria-labelledby="form:j_idt20" aria-autocomplete="list" aria-activedescendant="form:county_0" aria-describedby="form:county_0" aria-disabled="false">
</div>
<div class="ui-helper-hidden-accessible">
<select id="form:county_input" name="form:county_input" tabindex="-1" aria-hidden="true">
<option value="02" data-escape="true">BAKER COUNTY CLERK OF COURT</option>
<option value="04" data-escape="true">BRADFORD COUNTY CLERK OF COURT</option>
<option value="07" data-escape="true">CALHOUN COUNTY CLERK OF COURT</option>
<option value="12" data-escape="true">COLUMBIA COUNTY CLERK OF COURT</option>
<option value="14" data-escape="true">DESOTO COUNTY CLERK OF COURT</option>
<option value="15" data-escape="true">DIXIE COUNTY CLERK OF COURT</option>
<option value="19" data-escape="true">FRANKLIN COUNTY CLERK OF COURT</option>
<option value="21" data-escape="true">GILCHRIST COUNTY CLERK OF COURT</option>
<option value="22" data-escape="true">GLADES COUNTY CLERK OF COURT</option>
<option value="23" data-escape="true">GULF COUNTY CLERK OF COURT</option>
<option value="24" data-escape="true">HAMILTON COUNTY CLERK OF COURT</option>
</select>
</div>
<label id="form:county_label" class="ui-selectonemenu-label ui-inputfield ui-corner-all">BAKER COUNTY CLERK OF COURT</label>
這是我的代碼,我嘗試選擇漢密爾頓縣:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common import action_chains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
browser = webdriver.Chrome(filepath "chromedriver.exe", options = options)
browser.get("https://www.civitekflorida.com/ocrs/app/search.xhtml")
county = browser.find_element_by_xpath(".//select[@id='form:county_input']//option[value='24']")
這是我試圖與之互動的下拉選單,所以也許有某種方式可以擴展然后選擇?
uj5u.com熱心網友回復:
您搜索的元素僅在單擊下拉按鈕后出現 嘗試單擊下拉選單,然后單擊該選項
試試這個代碼:
browser.get("https://www.civitekflorida.com/ocrs/app/search.xhtml")
browser.find_element_by_xpath("//*[@id='form:county']/div[3]").click()
time.sleep(0.5)
county = browser.find_element_by_id("form:county_24")
print(county.text)
輸出:OKEECHOBEE 縣法院書記
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/454801.html
