1

I've looked at a few different answers to similar questions, but can't seem to figure out what's wrong with my specific situation. I've gone through most of my script to get where I want, but the authorize checkbox just can't seem to be found.

And in Python pretty simply:

### Authorize
driver.find_element('name', "d_1559640796736").click()

With the error:

NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"[name="d_1559640796736"]"}
  (Session info: chrome=109.0.5414.120)

I've tried every other way to find the element (id, css, xpath), but it's possible my xpath is just wrong. I have a feeling it has to do with the fact that it is a fieldset. I admit my Python is much better than my html.

Snapshot of the HTML:

html

2
  • Do these checks first, if this is inside iframe or it is not visible? Commented Feb 9, 2023 at 21:17
  • No iframe seems to be in the code. I had a similar issue earlier in my script where I had to switch to an iframe and was successful there. There is a hidden input above it, but I don't believe it has anything to do with the checkbox. Actually it could be. Yup, it has the same name. Commented Feb 9, 2023 at 21:26

2 Answers 2

1

The classname attribute values like d_1559640796736, h_1559640796736o1 are dynamically generated and is bound to chage sooner/later. They may change next time you access the application afresh or even while next application startup. So can't be used in locators.


Solution

The desired element is a dynamic element, so to click you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[value='Acknowledge'][name^='d_'][id^='d_'][id$='o1']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='Acknowledge' and starts-with(@name, 'd_')][starts-with(@id, 'h_') and contains(@id, 'o1')][starts-with(@id, 'h_') and contains(@id, 'o1')]"))).click()
    
  • 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
    
Sign up to request clarification or add additional context in comments.

1 Comment

The XPATH method worked perfectly. Thanks! I'll look into those locator strategies as many other find_element portions of my script use "name" or "id", with similar naming patterns. It seems to work daily, but who knows for how long.
0

Try below xpath instead of finding it by name

//input[@type='checkbox'][1]

You can select one by it's index if there are multiple checkboxes present.

Comments

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.