0

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_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?

Dave Smith
  • 103
  • 7

2 Answers2

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.

Surya
  • 4,446
  • 2
  • 17
  • 19
0

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()
Ludovic Viaud
  • 202
  • 1
  • 5
  • Tried it.Implicit waiting,that is.Didnt work.Here is the link to the modified code that I tried: http://pastebin.com/h620GyuV .BTW,I am following the docs from here for Python : http://selenium-python.readthedocs.org/en/latest/api.html – Dave Smith Nov 15 '14 at 16:51