samedi 4 février 2023

How to click on checkbox filter with selenium Python?

I'm trying to click on a checkbox filter on a website with selenium python. This is a part of its HTML code linked to one of the checkbox options.

<div class="shopee-checkbox" bis_skin_checked="1">
    <label class="shopee-checkbox__control">
        <input type="checkbox" name="" value="Jabodetabek">
        <div class="shopee-checkbox__box" bis_skin_checked="1">
            <i> </i>
        </div>
        <span class="shopee-checkbox__label">Jabodetabek</span>
    </label>
</div>

I tried following, but it didn't work.

import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get('https://shopee.co.id/search?keyword=baju%20laki-laki')

time.sleep(5)
driver.find_element(By.XPATH, "//input[@value='JABODETABEK']").click()

I read the answers to similar questions, mostly they suggest using 'id' and 'name' to find the element. However, in this input tag, there are only 'type' and 'value'.




Aucun commentaire:

Enregistrer un commentaire