radio_button_element.click()checkbox_button_element.click()
To select the radio button or checkbox, we just need to call the click() method on that element.
The click() method doesn't take any parameters and returns none. It just performs an action.
Let us take a look at an example of this.
from selenium import webdriver#specify where your chrome driver present in your pcPATH=r"C:\Users\gutkrish\Documents\chromedriver\chromedriver.exe"#get instance of web driverdriver = webdriver.Chrome(PATH)#provide website url heredriver.get("https://omayo.blogspot.com/")#locate radio button and click itdriver.find_element("id","radio2").click()#locate checkbox and click itdriver.find_element("id","checkbox2").click()
Line 1: We import the webdriver from the selenium package.
Line 5: We will be creating and passing a variable PATH with value as a path pointing to the web browser driver. For Chrome, it is the chromedriver.exe driver in the Windows environment.
Line 8: We get the instance of the webdriver.
Line 11: We provide the URL to the driver.get() method to open it in a browser.
Line 14: We find the radio button element using its id radio2 and call the click() method to select it.
Line 17: We find the checkbox element using its id checkbox2 and call the click() method to select it.
Free Resources