使用 Python Selenium 选择下拉菜单时遇到问题

Having trouble selecting dropdown with Python Selenium

我目前正在尝试网络抓取,以便自动执行一些工作搜索。我正在抓取的网站在这里: Wisconsin RETR(在 RETR 搜索下 - 高级以防页面显示不正确)。我正在尝试从下拉列表中选择 select“县名”,这样我就可以弄清楚如何添加名称,单击“添加”,然后单击“搜索”(很多未来的步骤需要弄清楚)。我最初的困难是我似乎无法访问该元素。查看页面源代码后,id=sCriteria 但是当我使用 driver.find_element(By.ID, 'sCriteria') 时,我收到一条错误消息“没有这样的元素:无法定位元素:{“方法”:“css select或","select或":[id="sCriteria"]"}。

我知道该元素在那里,因为我可以在页面源代码上看到它,但是无论我在网上搜索了一个下午之后尝试了什么,似乎都没有效果。此外,当我将其输入 Python、

ids=driver.find_elements_by_xpath('//*[id]')
for ii in ids:
    print(ii.get_attribute('id'))

我得到了一份 id 列表,我可以在网页中找到它,但它不包含我需要的列表。我认为它与嵌入在 Form1 内的 table 中的 id=sCriteria 有关,但老实说我不知道​​,而且我很确定它不在框架内。此外,这是与我尝试 select 的元素关联的 html 的屏幕截图。

wait=WebDriverWait(driver,60)     
driver.get("https://propertyinfo.revenue.wi.gov/WisconsinProd/search/advancedsearch.aspx?mode=advanced")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#btAgree"))).click()
box=Select(wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#sCriteria"))))
box.select_by_index(1)

要简单地抓住那个框和 select 任何元素,您可以使用以下等待元素。以及事先单击同意按钮。

进口:

from selenium.webdriver.support.select import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC