Using Selenium in Python to select a radio button

Question:

I am trying to make a bot that automates booking a study room (Microsoft booking). When I try to select the radio button, it doesn’t work. I tried using id and CSS_SELECTOR. I appreciate any help you can provide.

I want select room C, ID:service_2

room_c_select=driver.find_element(By.ID, "service_2")
room_c_select.click()

driver.find_element(By.CSS_SELECTOR,"input#service_2").click()

driver.find_element(By.CSS_SELECTOR,"[class='right serviceCard']input[type='radio'][id='service_2']")[0].click()
Asked By: Sam Bahrami

||

Answers:

You have to click on the small circle, i.e.

driver.find_elements(By.CSS_SELECTOR, 'span.image.icon-circleRegular')[1].click()
Answered By: sound wave

Using find_elements() to locate any specific element isn’t a part of the best practices as demonstrated by the other answer.

As per the html published as a comment, to click on the associated with the text Group Study Room C you can use the following locator strategy:

driver.find_element(By.XPATH, "//div[@class='name line-clamp' and text()='Group Study Room C']//ancestor::label[1]").click()
Answered By: undetected Selenium
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.