
Question:
I am trying to select No. of Rooms field Using Python Selenium from <a href="http://kolkata.quikr.com/post-classifieds-ads/?postadcategoryid=971" rel="nofollow">this</a> url.
My current code is:
inputBHK = driver.find_element_by_id("No_of_Rooms_newpap")
input1BHK = driver.find_element_by_id("No_of_Rooms1")
ActionChains(driver).click(inputBHK).click(input1BHK).perform()
Apart from the usual import and the Initialization. The exception Raised is:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: u'Offset within
element cannot be scrolled into view: (0, 0): [object HTMLInputElement]' ; Stacktrace:
Any ideas on how to proceed?
Answer1:try to wait between the 2 click events, the implementation of this site looks like tricky and slow <a href="http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp" rel="nofollow">http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp</a>
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()
Answer2: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.