1

I can't figure out why this don't work. The ID is obviously "ReservedDateTime_2022-08-29 14:10:00"

your help would be much appreciated

Index.html

<div data-function="timeTableCell" data-sectionid="40" data-servicetypeid="632" data-fromdatetime="2022-08-29 14:10:00" class="pointer timecell text-center " style="top: 620px; height:20px; background-color: #1862a8;color:#ffffff; position:relative;" aria-label="2022-08-29 14:10:00" role="row">

                            <script type="text/javascript">
                                                            document.writeln('14:10');
                            </script>14:10

                            <noscript>

                                            <label class="radio pointer inline-block" for="ReservedDateTime_2022-08-29 14:10:00">
                                                            <input type="radio" id="ReservedDateTime_2022-08-29 14:10:00" name="ReservedDateTime" value="2022-08-29 14:10:00"  />
                                                            14:10
                                            </label>
                            </noscript>
            </div>

Python

time.sleep(5)
driver.find_element_by_id("ReservedDateTime_2022-08-29 14:10:00").click()
>>
NoSuchElementException: no such element: Unable to locate element: {"method":"css     selector","selector":"[id="ReservedDateTime_2022-08-29 14:10:00"]"}
(Session info: chrome=99.0.4844.74)

The div is inside an tbody

2 Answers 2

1

This id

ReservedDateTime_2022-08-29 14:10:00

looks dynamic in nature since it has date and time.

I'd recommend you to use name instead:

name="ReservedDateTime"

or

CSS:

input[name='ReservedDateTime']

or XPath:

//input[@name='ReservedDateTime']

PS : Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the //input[@name='ReservedDateTime'] and see, if your desired element is getting highlighted with 1/1 matching node.

You can click it like below:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='ReservedDateTime']"))).click()

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.

2 Comments

Thank you for replying cruisepandey. I did the check and it looked good! What does it mean when the id is dynamic? The table contains a lot of dates and times and I'm only interested in ReservedDateTime_2022-08-29 14:10:00.
It could mean that for every time you launch a browser the value is different based on time. Glad we could solve it together, cheers!
0

Datetime may be dynamic for each instance, try with name instead.

driver.find_element(By.NAME, 'ReservedDateTime')

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.