Select checkbox using Selenium with Python

The checkbox HTML is:

<input id="C179003030-ORNL_DAAC-box" name="catalog_item_ids[]" type="checkbox" value="C179003030-ORNL_DAAC">

so you can use

browser.find_element_by_id("C179003030-ORNL_DAAC-box").click()

One way you can find elements' attributes is using the Google Chrome Developer Tools:

Inspect element


Use find_element_by_xpath with the XPath expression .//*[contains(text(), 'txt')] to find a element that contains txt as text.

browser.find_element_by_xpath(
    ".//*[contains(text(), '15 Minute Stream Flow Data: USGS (FIFE)')]"
).click()

UPDATE

Some contents are loaded after document load. I modified the code to try 10 times (1 second sleep in between).

import time

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException

browser = webdriver.Firefox()
url = 'http://reverb.echo.nasa.gov/reverb/'
browser.get(url)

for i in range(10):
    try:
        browser.find_element_by_xpath(
            ".//*[contains(text(), '15 Minute Stream Flow Data: USGS (FIFE)')]"
        ).click()
        break
    except NoSuchElementException as e:
        print('Retry in 1 second')
        time.sleep(1)
else:
    raise e

You can try in this way as well:

browser.find_element_by_xpath(".//*[@id='C179003030-ORNL_DAAC-box']")

If you want know if it's already checked or not:

browser.find_element_by_xpath(".//*[@id='C179003030-ORNL_DAAC-box']").get_attribute('checked')

to click:

browser.find_element_by_xpath(".//*[@id='C179003030-ORNL_DAAC-box']").click()