57916

Unable to select radio button with selenium in Python

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.

Recommend

  • selenium server launching two test execution tabs in firefox
  • What is the use of “arguments[0]” when implementing javascriptexecutor?
  • Selenium, automated frontend testing on different OS
  • How to start appium test on iOS simulator?
  • Captcha handling using Selenium
  • How to screenshot a specified WebElement in Selenium using Python
  • Selenium IDE - script execution time in output
  • Perform specialised functionality on failure of a Scalatest
  • How to test chat web app
  • Python: selenium-chromedriver error on new browser object
  • How to export Selenium Test Suite/Case as C#
  • Selenium Firefox WebDriver in WCF throwing “failed to start up socket within 45000 ms”
  • How do I retrieve the text in a table column using Selenium RC?
  • How to capture or listen to browser notifications?
  • Can you use multiple instances of Edge on a Selenium Grid Node?
  • How does `std::terminate` know to treat `std::exception`s specially?
  • JPA/Hibernate - Entity name seems to be important. If I rename to “Bob” works fine
  • Ability to use Bootstrap 3 grid system to specify width of select element
  • How to implement limit with Nhibernate and Sybase
  • HALF_PTR Windows data type
  • div fade-in when window is scrolled a certain distance from the top
  • How to define an array of floats in Shader properties?
  • Unable to click on the next page button containing “>” sign
  • SPARQL date range
  • A new chart every sheet
  • Less Conflicting Session Manager for Zope 2
  • Servlet stops working on Tomcat server after some hits or time
  • Selenium to click on a javascript button corresponding to a text
  • Does Mobilefirst provide a provision to access web services directly?
  • Install PHP intl extension on MacOS
  • Retrieve list of sent friend requests from friend_request FQL table
  • NHibernate Validation Localization with S#arp Architecture
  • Debugging ASP.NET on a built-in web server suddenly stops
  • Installing Hadoop, Java Exception about illegal characters at index 7?
  • How can I send an e-mail from a vbs script
  • Different response to non-authenticated users and AJAX calls
  • Accessing IRQ description array within a module and displaying action names
  • How to add a column to a Pandas dataframe made of arrays of the n-preceding values of another column
  • Hazelcast - OperationTimeoutException
  • Getting Messege Twice Using IMvxMessenger