python点击网页单选按钮_单击带有Python Selenium的单选按钮

importtimefromseleniumimportwebdriverfromselenium.webdriver.common.keysimportKeysbaseDomain="https://www.budgetdirect.com.au"startUrl=baseDomain+"/start/home.html"options=webdriver.ChromeOptions()options.add_experimental_option("excludeSwitches",["ignore-certificate- errors"])browser=webdriver.Chrome(chrome_options=options)browser.get(startUrl)#Selects the start dateel=browser.find_element_by_id('service_response_policy_policyBase_commencementDate')foroptioninel.find_elements_by_tag_name('option'):ifoption.text=='28/07/2015':option.click()#Selects the insurance typeel=browser.find_element_by_id('service_response_home_other_summarisedCoverType')foroptioninel.find_elements_by_tag_name('option'):ifoption.text=='Home':option.click()time.sleep(1)#Inserts Post codeinputElement=browser.find_element_by_id("service_response_icAddress_postCode")inputElement.send_keys('2000')time.sleep(1)inputElement.send_keys(Keys.ENTER)# simulates selecting the enter key#inserts street addressinputElement=browser.find_element_by_id("service_response_icAddress_streetSearch")inputElement.send_keys('161 Kent Street')time.sleep(1)inputElement.send_keys(Keys.TAB)# simulates selecting the enter key#inputElement.send_keys(Keys.ENTER)time.sleep(1)#Selects the ownership statusel=browser.find_element_by_id('service_response_home_occupancy_ownership_residenceOccupancyStatus')foroptioninel.find_elements_by_tag_name('option'):ifoption.text=='Owner Occupied':option.click()time.sleep(1)#Selects the year of moving inel=browser.find_element_by_id('service_response_home_occupancy_ownership_yearMovedIn')foroptioninel.find_elements_by_tag_name('option'):ifoption.text=='More than 5 years':option.click()time.sleep(1)#Selects the home typeel=browser.find_element_by_id('service_response_transactionData_homeType')foroptioninel.find_elements_by_tag_name('option'):ifoption.text=='Freestanding Home':option.click()####PROBLEM WITH CODE HERE#####Ticks no to body corporatebrowser.find_elements_by_xpath('.//input[@type="radio" and @value="N"]')[0].click# Unsuccessful to selectbrowser.find_element_by_id('service_response_home_homeFeatures_bodyCorporateStrataTitle_N').click()# Unsuccessful to selectforiinbrowser.find_elements_by_xpath('//*[@type="radio"]'):# Unsuccessful to selecttry:i.click()except:pass###############################

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值