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