Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

It would be nice if someone knows how to select the checkbox using Selenium with Python.

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox()

url = 'any url'

browser.get(url)

browser.find_element_by_id("15 Minute Stream Flow Data: USGS (FIFE)").click()

I want to select the checkbox corresponding to 15 Minute Stream Flow Data: USGS (FIFE.

I tried as id, name, link_text but could not detect what should be used?

1 Answer

0 votes
by (62.9k points)

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

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s automation testing training!

Browse Categories

...