1

I'm trying to find how can I see if this button (image) it's already clicked or not:

But I haven't been able to do it and I need to interact with this button because it allows me to edit the price of some items and protect them if I don't wan't, the problem is that I need to check if it's clicked or not before doing it.

I have tried many times to identify when it's clicked or not, but I don't see any change on button attributes so I don't know how to do it. I also tried checking on price item and I see one change when it's clicked:

When it's editable, there is an attribute named "contenteditable" and it's value equals true, but when it's not editable this attribute dissapear and changes for a attribute named "disabled" equals true:

This are the lines of code that I have been using to get this attribute values:

cod = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="tbodyDatos"]/tr[1]/td[5]/div'))).get_attribute("disabled")

cod = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="tbodyDatos"]/tr[1]/td[5]/div'))).get_attribute("attributes[1]")

cod = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="tbodyDatos"]/tr[1]/td[5]/div'))).get_attribute("attributes[1].nodeValue")

I would appreciate it so much if anyone can help me.

¡Thanks!

1
  • if it has the class fa-check-square-o, it's checked. Commented Feb 2, 2023 at 18:54

1 Answer 1

1

The expanded <i> along with it's decendants would have possibly given us some hint about some specific attribute to validate if the is checked or not.

checkbox


Solution

You can still probe the if the checkbox is checked or not with respect to the attribute of the adjascent <div> attribute as follows:

try:
    WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="tbodyDatos"]/tr[1]/td[5]/div'))).click()
    print("Checkbox unchecked")
except (TimeoutException, ElementNotInteractableException, WebDriverException):
    print("Checkbox checked")

Note : You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException, ElementNotInteractableException, WebDriverException
Sign up to request clarification or add additional context in comments.

1 Comment

After I post this question I found how to do it, thank you so much!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.