0

I've been trying to make this automation whereby it refreshes the page(by pressing the back button and pressing the search button), until slots come up in the search page. So I have created a for loop that presses the webelement search button and presses the back button back to return to the previous page. The excess code at the bottom is to make sure the program books the slot, but it usually does not reach those lines of code as I get the error.

However, after awhile of running the program, once i found a slot , and the back button becomes obsolete, I get the error NoSuchElementException, cannot find element button back(ref. bottom of qn), even when I have already indicated what the program should do when is unable to find the back button under the except column - which is then to proceed to the except block and select the slot that is available on the webpage

Side note:The program is able to run for awhile, refreshing the page so I'm certain that I have inputted the correct element path for the back button. However, I really cant figure out what is wrong with my except block such that my program does not automatically reach there and book the slots as indicated when the error pops up and instead, returns me the error in console

    no_slot = True
while no_slot == 1:
    for i in range(60):
        search_button = browser.find_element(By.NAME, "btnSearch")
        search_button.click()
        try:
            noslot_back_button = browser.find_element(By.CSS_SELECTOR, 'input[name="btnBack"]')
        except NoSuchElementException:
            # Proceed with booking
            slot_radio_info = browser.find_element(By.NAME, 'slot')
            slot_id = slot_radio_info.get_attribute('id')
            radio_button = browser.find_element(By.XPATH, '//input[@id="' + str(slot_id) + '"]')
            radio_button.click()
            slot_submit_button = browser.find_element(By.CSS_SELECTOR, 'input[value="Submit"]')
            slot_submit_button.click()
            double_cfm_button = browser.find_element(By.CSS_SELECTOR, 'input[value="Confirm"]')
            double_cfm_button.click()
            no_slot = False

This is the error received in console:

    Traceback (most recent call last):
  File "C:/Users/Jonathan/PycharmProjects/Riddle/BBDC_fullauto.py", line 81, in <module>
    noslot_back_button = browser.find_element(By.CSS_SELECTOR, 'input[name="btnBack"]')
  File "C:\Users\Jonathan\venvs\automation\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1238, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\Jonathan\venvs\automation\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Jonathan\venvs\automation\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"input[name="btnBack"]"}
  (Session info: chrome=95.0.4638.69)
Stacktrace:
Backtrace:
    Ordinal0 [0x00CC3AB3+2505395]
    Ordinal0 [0x00C5AE41+2076225]
    Ordinal0 [0x00B62498+1057944]
    Ordinal0 [0x00B8CB74+1231732]
    Ordinal0 [0x00BB6D92+1404306]
    Ordinal0 [0x00BA5A2A+1333802]
    Ordinal0 [0x00BB5168+1397096]
    Ordinal0 [0x00BA58BB+1333435]
    Ordinal0 [0x00B823E4+1188836]
    Ordinal0 [0x00B8323F+1192511]
    GetHandleVerifier [0x00E4CB36+1554566]
    GetHandleVerifier [0x00EF4A0C+2242396]
    GetHandleVerifier [0x00D50E0B+523099]
    GetHandleVerifier [0x00D4FEB0+519168]
    Ordinal0 [0x00C602FD+2097917]
    Ordinal0 [0x00C64388+2114440]
    Ordinal0 [0x00C644C2+2114754]
    Ordinal0 [0x00C6E041+2154561]
    BaseThreadInitThunk [0x7592FA29+25]
    RtlGetAppContainerNamedObjectPath [0x774E7A9E+286]
    RtlGetAppContainerNamedObjectPath [0x774E7A6E+238]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\Jonathan\PyCharm\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Users\Jonathan\PyCharm\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/Jonathan/PycharmProjects/Riddle/BBDC_fullauto.py", line 89, in <module>
    slot_submit_button.click()
  File "C:\Users\Jonathan\venvs\automation\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\Jonathan\venvs\automation\lib\site-packages\selenium\webdriver\remote\webelement.py", line 693, in _execute
    return self._parent.execute(command, params)
  File "C:\Users\Jonathan\venvs\automation\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Jonathan\venvs\automation\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input type="button" name="" value="Submit" class="btn" onclick="postBooking(this.form, 'b-TPDSBookingConfirm.asp?limit=TPDS', '', 'Please select a slot to book.')" onmouseover="blueBtnOver(this)" onmouseout="blueBtnOut(this)"> is not clickable at point (118, 330). Other element would receive the click: <td align="right" class="bluetxtbold">...</td>
  (Session info: chrome=95.0.4638.69)
Stacktrace:
Backtrace:
    Ordinal0 [0x00CC3AB3+2505395]
    Ordinal0 [0x00C5AE41+2076225]
    Ordinal0 [0x00B62498+1057944]
    Ordinal0 [0x00B92C09+1256457]
    Ordinal0 [0x00B90F48+1249096]
    Ordinal0 [0x00B8ED0D+1240333]
    Ordinal0 [0x00B8DB68+1235816]
    Ordinal0 [0x00B83857+1194071]
    Ordinal0 [0x00BA59F3+1333747]
    Ordinal0 [0x00B83676+1193590]
    Ordinal0 [0x00BA5ADA+1333978]
    Ordinal0 [0x00BB5168+1397096]
    Ordinal0 [0x00BA58BB+1333435]
    Ordinal0 [0x00B823E4+1188836]
    Ordinal0 [0x00B8323F+1192511]
    GetHandleVerifier [0x00E4CB36+1554566]
    GetHandleVerifier [0x00EF4A0C+2242396]
    GetHandleVerifier [0x00D50E0B+523099]
    GetHandleVerifier [0x00D4FEB0+519168]
    Ordinal0 [0x00C602FD+2097917]
    Ordinal0 [0x00C64388+2114440]
    Ordinal0 [0x00C644C2+2114754]
    Ordinal0 [0x00C6E041+2154561]
    BaseThreadInitThunk [0x7592FA29+25]
    RtlGetAppContainerNamedObjectPath [0x774E7A9E+286]
    RtlGetAppContainerNamedObjectPath [0x774E7A6E+238]
python-BaseException
  • When asking a question on stackoverflow it's good practice to give the full stack trace since knowing which line is throwing the error helps debugs it. I haven't dived too deeply into your problem but if an error appears in a `try except` block it can mean that the error is happening IN your except block. – kkawabat Nov 06 '21 at 00:17
  • This may sound silly, but you can try using the old 'print' to track what actually occurred at each step of time. – Larry the Llama Nov 06 '21 at 07:16
  • Hi @kkawabat I have updated it. Sorry I'm new to this but stack trace means the error message right? Regarding the except block. I suspect the error isnt there because the error - Cannot find element name "button back" is referring to the code before the except block? –  Nov 06 '21 at 12:01

1 Answers1

0

This isn't the answer but I could not fit it in the comments because of character limits.

Continuation of the comments:

@ToangarashiWoon stack trace means more than the error message but in this context yes. So looking at the stack trace you can see that the actual error happened at slot_submit_button.click().

If you read the stack trace you see that the line

noslot_back_button = browser.find_element(By.CSS_SELECTOR, 'input[name="btnBack"]')

threw an error, this is expected however if you kept reading the stack trace you see the line:

During handling of the above exception, another exception occurred:

What this tells you is that there was an exception in the except block. More specifically on:

 File "C:/Users/Jonathan/PycharmProjects/Riddle/BBDC_fullauto.py", line 89, in <module>
    slot_submit_button.click() 

with the error message:

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <input type="button" name="" value="Submit" class="btn" onclick="postBooking(this.form, 'b-TPDSBookingConfirm.asp?limit=TPDS', '', 'Please select a slot to book.')" onmouseover="blueBtnOver(this)" onmouseout="blueBtnOut(this)"> is not clickable at point (118, 330). Other element would receive the click: <td align="right" class="bluetxtbold">...</td>

Based on this error message it seems the problem is that you aren't able to click on this because a td element is blocking the button.

Dharman
  • 30,962
  • 25
  • 85
  • 135
kkawabat
  • 1,530
  • 1
  • 14
  • 37
  • Hey thanks so much for helping. However, could you explain to me what and how do you access the button. Does it have to do with the timing of clicking the element? Perhaps after selecting the radio button, it takes awhile for the system to process. Only after that, then i should be selecting the submit button? This is my assumption, correct me if im wrong haha –  Nov 07 '21 at 13:00
  • I don't know enough about selenium, but googling th error message I found this https://stackoverflow.com/questions/62903056/elementclickinterceptedexception-message-element-click-intercepted-element-is Maybe this will be useful for you – kkawabat Nov 07 '21 at 23:48