3

I'm trying to check the checkbox on a page: https://www.pkobp.pl/poi/?clients=1,2,3.

<li class="poi-filter-top__el"> <div class="poi-icon poi-icon--facility"></div> <input type="checkbox" id="poi-legend-facility" class="js-poi-legend" name="type" value="facility"> <label for="poi-legend-facility" class="poi-legend input-checkbox poi-filter-top__label">Oddział</label> <a href="#facility" class="js-poi-action poi-filter-top__link" data-action="facility">Wybierz rodzaj</a> </li> 

I try to do this with:

checkboxes = driver.find_elements_by_id("poi-legend-facility") for checkbox in checkboxes: if not checkbox.is_selected(): checkbox.click() 

But it doesn't work. Can you help me?

1
  • is there are multiple checkboxesCommentedNov 1, 2017 at 12:36

3 Answers 3

5

You have only one checkbox with such ID (poi-legend-facility).

You can do like this:

checkbox = driver.find_element_by_id("poi-legend-facility") if not checkbox.is_selected(): checkbox.click() 

Or in your case try this code:

checkboxes = driver.find_elements_by_id("poi-legend-facility") checkboxes[0].click() 

PS: Using ID for finding element faster than finding by XPath.

1
  • Nice answer, @RatmirAsanovCommentedNov 1, 2017 at 13:25
1

This is the the only way I could find to check all the boxes in that page and break out of loop. Give this a shot as well.

from selenium import webdriver import time driver = webdriver.Chrome() driver.get('https://www.pkobp.pl/poi/?clients=1,2,3') for tickbox in driver.find_elements_by_css_selector(".input-checkbox"): try: tickbox.click() time.sleep(7) except: break driver.quit() 
    0

    Try this xpath

    checkElements= driver.find_element_by_xpath("//input[@type='checkbox' and @value='facility']") checkElements.click() 

    I don't know python so might be syntax error but path is correct

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.