1

I'm relatively new to coding and kinda unfamiliar with stacktrace errors. I have been given this error, but im not sure which part of my code do i fix? Did the error come up because of a NoSuchElementException, or was it due to a timeout error?

I thought that within my code I had dealt with how the program will face the nosuchelement exception. Basically, my code searches for slots that are available and will disable the back button when a slot becomes available. However, I am met with other sorts of error such as connection time out when the webpage has been idle for too long. Thus, my mission now is to filter out the different problems i am faced with so that i can deal with the issues respectively. I have added the expected conditions as the filter to differentiate the errors i am faced with

Code:

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:
            if EC.presence_of_element_located(browser.find_element(By.XPATH, '//td[@class="title"]')):
                # Proceed with booking (make sure that it is at the booking page (implementation)
                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"]')
                WebDriverWait(EC.element_to_be_clickable(slot_submit_button))
                slot_submit_button.click()
                double_cfm_button = browser.find_element(By.CSS_SELECTOR, 'input[value="Confirm"]')
                double_cfm_button.click()
            elif not EC.title_contains('BBDC: Booking For TP Driving Simulator Lesson'):
                print("Connection timed out or something else happened")
            else:
                print("unaccounted condition")

Error received:

Traceback (most recent call last):
  File "C:/Users/Jonathan/PycharmProjects/Riddle/BBDC.py", line 83, 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 [0x00723AB3+2505395]
    Ordinal0 [0x006BAE41+2076225]
    Ordinal0 [0x005C2498+1057944]
    Ordinal0 [0x005ECB74+1231732]
    Ordinal0 [0x00616D92+1404306]
    Ordinal0 [0x00605A2A+1333802]
    Ordinal0 [0x00615168+1397096]
    Ordinal0 [0x006058BB+1333435]
    Ordinal0 [0x005E23E4+1188836]
    Ordinal0 [0x005E323F+1192511]
    GetHandleVerifier [0x008ACB36+1554566]
    GetHandleVerifier [0x00954A0C+2242396]
    GetHandleVerifier [0x007B0E0B+523099]
    GetHandleVerifier [0x007AFEB0+519168]
    Ordinal0 [0x006C02FD+2097917]
    Ordinal0 [0x006C4388+2114440]
    Ordinal0 [0x006C44C2+2114754]
    Ordinal0 [0x006CE041+2154561]
    BaseThreadInitThunk [0x7739FA29+25]
    RtlGetAppContainerNamedObjectPath [0x77987A9E+286]
    RtlGetAppContainerNamedObjectPath [0x77987A6E+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.py", line 86, in <module>
    if EC.presence_of_element_located(browser.find_element(By.XPATH, '//td[@class="title"]')):
  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":"xpath","selector":"//td[@class="title"]"}
  (Session info: chrome=95.0.4638.69)
Stacktrace:
Backtrace:
    Ordinal0 [0x00723AB3+2505395]
    Ordinal0 [0x006BAE41+2076225]
    Ordinal0 [0x005C2498+1057944]
    Ordinal0 [0x005ECB74+1231732]
    Ordinal0 [0x00616D92+1404306]
    Ordinal0 [0x00605A2A+1333802]
    Ordinal0 [0x00615168+1397096]
    Ordinal0 [0x006058BB+1333435]
    Ordinal0 [0x005E23E4+1188836]
    Ordinal0 [0x005E323F+1192511]
    GetHandleVerifier [0x008ACB36+1554566]
    GetHandleVerifier [0x00954A0C+2242396]
    GetHandleVerifier [0x007B0E0B+523099]
    GetHandleVerifier [0x007AFEB0+519168]
    Ordinal0 [0x006C02FD+2097917]
    Ordinal0 [0x006C4388+2114440]
    Ordinal0 [0x006C44C2+2114754]
    Ordinal0 [0x006CE041+2154561]
    BaseThreadInitThunk [0x7739FA29+25]
    RtlGetAppContainerNamedObjectPath [0x77987A9E+286]
    RtlGetAppContainerNamedObjectPath [0x77987A6E+238]

python-BaseException
Traceback (most recent call last):
  File "C:\Users\Jonathan\PyCharm\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 292, in _on_run
    r = self.sock.recv(1024)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Process finished with exit code 1
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

0

Selenium is unable to locate the element noslot_back_button = browser.find_element(By.CSS_SELECTOR, 'input[name="btnBack"]') most likely a typo or maybe you forgot to name the css selector.

Gourab Paul
  • 11
  • 1
  • 2
  • I wna know what this means too python-BaseException Traceback (most recent call last): File "C:\Users\Jonathan\PyCharm\plugins\python-ce\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 292, in _on_run r = self.sock.recv(1024) TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond Process finished with exit code 1 –  Nov 09 '21 at 06:11
  • maybe you forgot to respond from the api. – Gourab Paul Nov 09 '21 at 14:44
0

This error message...

Traceback (most recent call last):
.
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 [0x00723AB3+2505395]
    Ordinal0 [0x006BAE41+2076225]
    Ordinal0 [0x005C2498+1057944]

...implies that NoSuchElementException was raised while locating the elements.


Addressing NoSuchElementException

Without the relevant HTML of the element it would be difficult to address if the Locator Strategy identifies the element uniquely within the HTML DOM.

Additionally, though you are using chrome=95.0.4638.69 but your ChromeDriver version isn't in sync with the Chrome browser version. Hence you see the Backtrace.


Solution

Ensure that:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Hi @Debanjan8 thanks so much for your detailed explanation. However, I am a little confused about your statement: Without the relevant HTML of the element it would be difficult to address if the Locator Strategy identifies the element uniquely within the HTML DOM. Currently, I have only learned about python and not HTML / Java script so if you could explain it in simple terms, it would really be appreciated!! Also, regarding the ChromeDriver, mine is updated to the latest version of V95.0 level which is the same as my Chrome browser. –  Nov 10 '21 at 06:03
  • I'm not asking you to learn HTML :) but to copy the HTML of the element from the [DOM Tree](https://javascript.info/dom-nodes). Errors with Backtrace is not that common but does arises. Don't have any refence handy atm but will share with you soon. – undetected Selenium Nov 10 '21 at 07:47