Answer a question

I want to select a radio button with selenium in python. I have tested with 3 solutions. Unfortunately it doesn't work at all. Could you do me a favor and help me. I am totally beginner. The URL: https://biruni.tuik.gov.tr/disticaretapp/menu_ing.zul

enter image description here

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome('C:\Webdriver\chromedriver.exe')
driver.get('https://biruni.tuik.gov.tr/disticaretapp/menu_ing.zul')
time.sleep(2)
driver.maximize_window()
element = driver.find_element(by=By.XPATH,value='//*[contains(text(), "Product/Product Groups-Partner Country")]')                                                                                                            
element.click()
time.sleep(4)

# radio = driver.find_element_by_id("o1BQ41-real")
# radio.click()


# l=driver.find_element_by_xpath('//*[@id="o1BQ41-real"]')
# l.click()


# driver.find_element_by_css_selector("input#o1BQ41-real").click() 

time.sleep(10)

Answers

You can use the same select by text to click on the radio button.

radio_element = driver.find_element(by=By.XPATH,value='//*[contains(text(), "Product/Partner Country")]')
radio_element.click()

This selects the desired element

enter image description here

or you can also select the element by id

radio_element = driver.find_element(by=By.XPATH,value='//span[@id="bKFP41"]')
radio_element.click()
Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐