browser timeout #3383
              
                
                  
                  
                    Answered
                  
                  by
                    mdmintz
                  
              
          
                  
                    
                      IndrajeethY
                    
                  
                
                  asked this question in
                Q&A
              
            
            
              browser timeout
            
            #3383
          
          
        -
| can i add a timeout to exit browser automatically? coz sometimes the site i am trying to access is unresponsive or loads for long time i want to add a timeout to auto exit code is it possible to do so? def launch(self, username, password):
        attempt = 0
        while attempt < self.retries and not self.stop_flag:
            try:
                with SB(uc=True) as sb:
                    logger.info(f"Trying to login with {username}")
                    sb.activate_cdp_mode(self.url)
                    sb.uc_gui_click_captcha()
                    sb.send_keys(
                        "input[name='LoginForm[username]']", username, timeout=10
                    )
                    sb.send_keys(
                        "input[name='LoginForm[password]']", password, timeout=10
                    )
                    sb.wait_for_element_visible("img#yw0", timeout=10)
                    screenshot_name = f"captcha_{uuid.uuid4()}.png"
                    if sb.is_element_visible("img#yw0"):
                        captcha_image = sb.get_element("img#yw0")
                        captcha_image.save_screenshot(screenshot_name)
                        logger.info(f"Screenshot saved: {screenshot_name}")
                    captcha_solution = self.solve_captcha_truecaptcha(screenshot_name)
                    sb.send_keys(
                        "input[name='LoginForm[verifyCode]']", captcha_solution
                    )
                    logger.info(f"Filled in the login form for {username}")
                    sb.click('button[type="submit"]')
            except Exception as e:
                attempt += 1
                logger.info(f"Attempt {attempt} failed: {e}")
                sleep(2)
        logger.info(f"All {self.retries} attempts failed for {self.url}")this is my code it handles everything like if element not found etc but want to introduce a timeout., how to do so? | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            mdmintz
          
      
      
        Jan 2, 2025 
      
    
    Replies: 1 comment
-
| As in the example here:you can set the page_load_strategy, (pls="none"), to prevent extra waiting. | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
      Answer selected by
        mdmintz
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
As in the example here:
SeleniumBase/examples/cdp_mode/raw_socialblade.py
Line 4 in 11e81b0
page_load_strategy, (pls="none"), to prevent extra waiting.