Script Freezes in Seleniumbase

  Kiến thức lập trình

When I run the .exe of my script (based on Seleniumbase framework), after some time (about 60 minutes), the script stops unexpectedly. The script opens 3 tabs with 3 links and switches between tabs to check if a specific element is present on the webpage, with a timeout of 0.1 seconds: sb.assert_element_present("//li[@class='onsale but']//div[contains(text(),'32,80 €')]",timeout=0.1)

What could be causing the script to freeze after a while? Could it be that switching tabs too quickly is causing the issue? How can I optimize the code?

I look forward to your response, thank you in advance. I really appreciate your work.

Here is the complete code:

with SB(is_mobile=True,headless2=False,user_data_dir=user_data_dir,chromium_arg=chromium_arg) as sb:
    sb.driver.maximize_window()
    for url in urls:

        sb.execute_script(f"window.open('{url}');")
    
    time.sleep(1)

    ventanas = sb.driver.window_handles

    lista_buenas = []
    while True:
    
        if len(lista_buenas) == len(urls):
        
            break

        for x in range(1,len(ventanas)):
        
            if x not in lista_buenas:
                sb.switch_to_window(sb.driver.window_handles[x])
                try:
                    sb.driver.switch_to_frame("iframe[sandbox='allow-scripts allow-same-origin allow-forms']")
                    sb.refresh()
                except:
                    nombrito = sb.get_text("//header[@data-pw-test-id='event-header']//h1/span")
                    print(f"(+) Todo bien en {nombrito}")
                    lista_buenas.append(x)
            else:
                continue

    sb.switch_to_window(sb.driver.window_handles[0])
    sb.driver.close()
    time.sleep(1)
    nuevas = sb.driver.window_handles
    
    #this is the main code
    while True:
        try:
            for x in range(len(nuevas)):
                
                sb.switch_to_window(nuevas[x])
                
                nombre_evento = sb.get_text("//header[@data-pw-test-id='event-header']//h1/span")
                sb.click("//button[@data-button-tracking-id='toggle-tickets-modal-open']",scroll=False)
    
                try:
                    sb.switch_to_frame("//iframe[@id='#tickets-iframe-s']")
            
                except:
                    print("(-) HA TARDADO EN CARGAR...")
                    pass    

                try:
                
                    sb.assert_element_present("//li[@class='onsale but']//div[contains(text(),'32,80 €')]",timeout=0.1)
                    mensaje = f"Entrada encontrada para el evento: {nombre_evento}"
                    telegram(mensaje)

        
                    sb.switch_to_default_content()
                    sb.click('//button[@data-button-tracking-id="toggle-tickets-modal-closed"]')
                    
                except:
                    sb.switch_to_default_content()
                    sb.click('//button[@data-button-tracking-id="toggle-tickets-modal-closed"]')
                    continue
        except KeyboardInterrupt:
            print("Saliendo...")
            break
    
sb.driver.quit()

I ran a script that opens 3 tabs, checks for a specific element on each webpage, and switches between tabs to verify the presence of the element. I expected the script to run continuously without issues. However, after about 60 minutes, the script unexpectedly stops or freezes.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT