So, there's a site I'm trying to parse so it can automatically raising my offers every two hours. The site designed in that way that you have to mark with checkboxes the lots you want to raise. Somehow in html code the checkbox doesn't have value, instead it looks like this:
I have to click it manually via using
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "idk what to write so it checks it"))).click()
But I really don't know how do I find it so it can be clicked.
<label>
<input type="checkbox" value="613" checked="">
# value - lot id, checked - means the checkbox is marked
<label>
# and non-checked checkbox code looks like this:
<label>
<input type="checkbox" value="613">
<label>
CodePudding user response:
You can't use By.CLASS_NAME
here since it has no class
.
You can use:
By.CSS_SELECTOR
to find by CSS selectors
chbVal = '613' # in case you need be able to change this
(By.CSS_SELECTOR, f'label > input[type="checkbox"][value="{chbVal}"][checked=""]') # for checked
(By.CSS_SELECTOR, f'label > input[type="checkbox"][value="{chbVal}"]:not([checked])') # for unchecked
chbVal = '613' # in case you need be able to change this
(By.XPATH, f'//label/input[@type="checkbox"][@value="{chbVal}"][@checked=""]') # for checked
(By.XPATH, f'//label/input[@type="checkbox"][@value="{chbVal}"][not(@checked="")]') # for unchecked
Note: These are just based on the html snippet you've included - there might by parent elements with better identifiers that you need to include in your path/selector.
Also,
Somehow in html code the checkbox doesn't have value
but in your snippet it does have value
...? Anyway, the examples above include value
, but you don't have to include them; you can even exclude them with not(...)
as shown for checked
. (Btw, not(checked)
/not(@checked)
should exclude elements that have a checked
attribute at all, no matter what the value is.)