0

I'm trying to select the radio button 'Government & Military' on this page using Selenium.

The code below tries two different methods, but neither are working:

from selenium import webdriver
browser = webdriver.Chrome('/Users/Joe/Python/chromedriver')

browser.find_element_by_xpath('//*[@id="propertygov"]').click()
browser.find_elements_by_xpath('.//*[@id="propertygov"]')[0].click()

Edit:

Here is the full code. The initial interaction with the date form is keeping me from selecting the radio select:

from selenium import webdriver

browser = webdriver.Chrome('/Users/Joe/Python/chromedriver')
browser.get("http://www.marriott.com/search/default.mi")

browser.find_element_by_id('editsearch-location').send_keys('Atlanta, GA')
browser.find_element_by_xpath('//*[@id="hotel-fromDate"]').click()

browser.find_element_by_xpath('//*[@id="hotel-fromDate_table"]/tbody/tr[2]/td[2]/div').click()
browser.find_element_by_xpath('//*[@id="hotel-fromDate_table"]/tbody/tr[2]/td[3]/div').click()

browser.find_element_by_id('propertygov').click()
2
  • If you have the id why are you using find by xpath? try find_element_by_id('propertygov') Commented Feb 7, 2016 at 23:32
  • I just tried that and it did not work. Commented Feb 7, 2016 at 23:34

1 Answer 1

2
browser.get("http://www.marriott.com/search/default.mi")
browser.find_element_by_id('propertygov').click()
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah just realized he was not hitting the url
This does work. I should have posted my full code. I think the problem is that my initial interaction with the date form is interfering with me being able to select the radio button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.