Skip to content Skip to sidebar Skip to footer

Unable To Select Radio Button With Selenium In Python

I am trying to select No. of Rooms field Using Python Selenium from this url. My current code is: inputBHK = driver.find_element_by_id('No_of_Rooms_newpap') input1BHK = driver.find

Solution 1:

Use XPATH locator to find & click required radio button as below:

 input1BHK = driver.find_element_by_xpath("//*[@id='No_of_Rooms_l4Attr_RadioBox_div']//span[contains(text(),'1 BHK')]")
 input1BHK.click()

It will select the 1st option '1 BHK', you can update the XPATH to select any other required option.

Solution 2:

try to wait between the 2 click events, the implementation of this site looks like tricky and slow http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

edit: OK I found something, there is some problems with tricky drop down list like in this website, they use hidden radio button, so instead of click it we will click on the label which contains the radio button (it works also on the span element which contains the text, if you prefer select by text())

from selenium import webdriver

URL = 'http://kolkata.quikr.com/post-classifieds-ads/?postadcategoryid=971'

driver = webdriver.Firefox()
driver.get(URL)

inputBHK = driver.find_element_by_id("No_of_Rooms_newpap")
inputBHK.click()

container = driver.find_element_by_id("No_of_Rooms_l4Attr_RadioBox_div")
input1BHK = container.find_element_by_xpath(".//label[1]")
input1BHK.click()

Post a Comment for "Unable To Select Radio Button With Selenium In Python"