Я пытаюсь выбрать переключатель с помощью Python Selenimum. Я уже пробовал все выпущенные решения, но на данный сайт ничего не работает. Мой полный код:Нажмите переключатель с Python Selenium
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
baseDomain = "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 date
el = browser.find_element_by_id('service_response_policy_policyBase_commencementDate')
for option in el.find_elements_by_tag_name('option'):
if option.text == '28/07/2015':
option.click()
#Selects the insurance type
el = browser.find_element_by_id('service_response_home_other_summarisedCoverType')
for option in el.find_elements_by_tag_name('option'):
if option.text == 'Home':
option.click()
time.sleep(1)
#Inserts Post code
inputElement = 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 address
inputElement = 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 status
el = browser.find_element_by_id('service_response_home_occupancy_ownership_residenceOccupancyStatus')
for option in el.find_elements_by_tag_name('option'):
if option.text == 'Owner Occupied':
option.click()
time.sleep(1)
#Selects the year of moving in
el = browser.find_element_by_id('service_response_home_occupancy_ownership_yearMovedIn')
for option in el.find_elements_by_tag_name('option'):
if option.text == 'More than 5 years':
option.click()
time.sleep(1)
#Selects the home type
el = browser.find_element_by_id('service_response_transactionData_homeType')
for option in el.find_elements_by_tag_name('option'):
if option.text == 'Freestanding Home':
option.click()
####PROBLEM WITH CODE HERE####
#Ticks no to body corporate
browser.find_elements_by_xpath('.//input[@type="radio" and @value="N"]')[0].click # Unsuccessful to select
browser.find_element_by_id('service_response_home_homeFeatures_bodyCorporateStrataTitle_N').click() # Unsuccessful to select
for i in browser.find_elements_by_xpath('//*[@type="radio"]'): # Unsuccessful to select
try:
i.click()
except:
pass
###############################
Код работает нормально, пока не будет выбран переключатель. Как показано, я попробовал несколько методов для выбора переключателя, но ничего не работает. Любые идеи приветствуются!
она невидима. Вы не можете щелкнуть элемент, невидимый. – LittleQ