Arpit Mundra
Arpit Mundra

Reputation: 41

Python Selenium: How to select a radio button?

I know this question has been asked previously but none of the previous answers are helping me here.

I need to scrape a table which is generated by selecting one of the radio buttons on this page - https://www.oeko-tex.com/en/business/oeko_tex_certified_products/oeko_tex_certified_products.html

My code so far -

driver.get("https://www.oeko-tex.com/en/business/oeko_tex_certified_products/oeko_tex_certified_products.html")
time.sleep(2)
radio = driver.find_element_by_xpath(".//input[@type='radio' and @value='step']")    
time.sleep(2)
radio.click()

From what I understand, the xpath is not valid here.

Upvotes: 0

Views: 54

Answers (1)

Kamal
Kamal

Reputation: 2554

The xpath you are using is valid. The issue is that the radio button is inside a frame. So you need to switch to that frame and then search for this element.

Add this before searching for the radio button:

driver.switch_to.frame(driver.find_element_by_tag_name('iframe'))

And I would also suggest to use webdriverwait instead of time.sleep calls.

Upvotes: 1

Related Questions