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###############################
python点击网页单选按钮_单击带有Python Selenium的单选按钮
最新推荐文章于 2022-09-28 14:14:24 发布