[Python] Select check box using Selenium

如果判斷 checkbox 並自動打勾。

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.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *