pythonselenium-webdriverweb-search

python - TimeoutException Traceback (most recent call last)


I am using selenium to retrieve the SSIC description, based on the UEN of the company, and to print the results. I am however, receiving the following error message upon running the code:

TimeoutException                          Traceback (most recent call last)
<ipython-input-42-80250277515b> in <module>
     10     submit = d.find_element(By.ID, "pt1:r1:0:sv1:cb1")
     11     submit.click()
---> 12     ssic = WebDriverWait(d,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".bizpara1 text_uppercase")))
     13 
     14     print(ssic)

~\Anaconda3\lib\site-packages\selenium\webdriver\support\wait.py in until(self, method, message)
     93             if time.monotonic() > end_time:
     94                 break
---> 95         raise TimeoutException(message, screen, stacktrace)
     96 
     97     def until_not(self, method, message: str = ""):

TimeoutException: Message: 
Stacktrace:
    GetHandleVerifier [0x00007FF63BCB78A2+54818]
    (No symbol) [0x00007FF63BC26AD2]
    (No symbol) [0x00007FF63BADDA3B]
    (No symbol) [0x00007FF63BB1E4FC]
    (No symbol) [0x00007FF63BB1E67C]
    (No symbol) [0x00007FF63BB59627]
    (No symbol) [0x00007FF63BB3EAEF]
    (No symbol) [0x00007FF63BB575A2]
    (No symbol) [0x00007FF63BB3E883]
    (No symbol) [0x00007FF63BB13691]
    (No symbol) [0x00007FF63BB148D4]
    GetHandleVerifier [0x00007FF63C01B9A2+3610402]
    GetHandleVerifier [0x00007FF63C071870+3962352]
    GetHandleVerifier [0x00007FF63C069D5F+3930847]
    GetHandleVerifier [0x00007FF63BD53656+693206]
    (No symbol) [0x00007FF63BC31638]
    (No symbol) [0x00007FF63BC2D944]
    (No symbol) [0x00007FF63BC2DA72]
    (No symbol) [0x00007FF63BC1E123]
    BaseThreadInitThunk [0x00007FF8FF0E7344+20]
    RtlUserThreadStart [0x00007FF8FF8E26B1+33]

Code that I'm using:

d = webdriver.Chrome()
search = ['199904446R', '200514781N', '198500528C']


for UEN in search: 
    d.get('https://www.tis.bizfile.gov.sg/ngbtisinternet/faces/oracle/webcenter/portalapp/pages/TransactionMain.jspx?selectedETransId=dirSearch')
    e = d.find_element(By.ID, "pt1:r1:0:sv1:it1::content")
    e.click()
    e.send_keys(UEN)
    submit = d.find_element(By.ID, "pt1:r1:0:sv1:cb1")
    submit.click()
    ssic = WebDriverWait(d,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".bizpara1 text_uppercase")))

    print(ssic)

For the SSIC element, below is the span details:

''<div><span class='bizpara1 text_uppercase'>GENERAL CONTRACTORS (NON-BUILDING CONSTRUCTION)</span></div>''

Will greatly appreciate any help in rectifying the issue pls.


Solution

  • You have 4 issues there.

    1. You should wait for input visibility as far as site is loaded async.
    2. You locator is incorrect. It should be .bizpara1.text_uppercase if you are searching element by CSS_SELECTOR, your locator implementation is correct for searching by CLASS_NAME.
    3. Actually, you are getting first element with this locator, when your ssid is last element from array. So you should use condition visibility_of_all_elements_located and get last element from array.
    4. I guess, you need to print element text, and not element reference.
    wait = WebDriverWait(driver, 10)
    search = ['199904446R', '200514781N', '198500528C']
    
    for UEN in search:
        driver.get('https://www.tis.bizfile.gov.sg/ngbtisinternet/faces/oracle/webcenter/portalapp/pages/TransactionMain.jspx?selectedETransId=dirSearch')
        uen_input = wait.until(EC.visibility_of_element_located((By.ID, "pt1:r1:0:sv1:it1::content")))
        uen_input.click()
        uen_input.send_keys(UEN)
        submit = driver.find_element(By.ID, "pt1:r1:0:sv1:cb1")
        submit.click()
        ssic = wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".bizpara1.text_uppercase")))[-1]
    
        print(ssic.text)