简体   繁体   English

Python Selenium Webdriver选择下拉值

[英]Python Selenium Webdriver Select Dropdown Value

I'm trying to automate the search process in this website: https://www.bcbsga.com/health-insurance/provider-directory/searchcriteria The process involves clicking on the "Continue" button to search under the 'guest' mode. 我正在尝试自动执行此网站中的搜索过程: https : //www.bcbsga.com/health-insurance/provider-directory/searchcriteria该过程涉及单击“继续”按钮以在“来宾”模式下进行搜索。 The next page has got a list of drop-down items to refine the search criteria. 下一页具有下拉列表以完善搜索条件。 My code either produces the "Element not visible" exception (which I corrected by using a wait) or times out. 我的代码要么生成“元素不可见”异常(通过使用等待来纠正),要么超时。 Please help. 请帮忙。

Here's my code: 这是我的代码:

# 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()

you can use input search and key.return: 您可以使用输入搜索和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