簡體   English   中英

Python Selenium Webdriver選擇下拉值

[英]Python Selenium Webdriver Select Dropdown Value

我正在嘗試自動執行此網站中的搜索過程: https : //www.bcbsga.com/health-insurance/provider-directory/searchcriteria該過程涉及單擊“繼續”按鈕以在“來賓”模式下進行搜索。 下一頁具有下拉列表以完善搜索條件。 我的代碼要么生成“元素不可見”異常(通過使用等待來糾正),要么超時。 請幫忙。

這是我的代碼:

# navigate to the desired page
driver.get("https://www.bcbsga.com/health-insurance/provider-directory/searchcriteria")
# get the guest button
btnGuest = driver.find_element_by_id("btnGuestContinue")
#click the guest button
btnGuest.click()
wait = WebDriverWait(driver,10)
#Find a Doctor Search Criteria page
element = wait.until(EC.visibility_of_element_located((By.ID,"ctl00_MainContent_maincontent_PFPlanQuestionnaire_ddlQuestionnaireInsurance")))
lstGetInsurance = Select(element)
lstGetInsurance.select_by_value("BuyMyself$14States")

# close the browser window
#driver.quit()

您可以使用輸入搜索和key.return:

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

divID = 'ctl00_MainContent_maincontent_PFPlanQuestionnaire_ddlQuestionnaireInsurance_chosen'
inputID = 'ctl00_MainContent_maincontent_PFPlanQuestionnaire_ddlQuestionnaireInsurance_chosen_input'
inputValue = 'I buy it myself (or plan to buy it myself)'

driver = webdriver.Chrome()

driver.get("https://www.bcbsga.com/health-insurance/provider-directory/searchcriteria")
driver.find_element_by_id("btnGuestContinue").click()
driver.implicitly_wait(10)
driver.find_element_by_id(divID).click()
driver.find_element_by_id(inputID).send_keys(inputValue)
driver.find_element_by_id(inputID).send_keys(Keys.RETURN)
time.sleep(6)
driver.close()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM