-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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.
All reactions
Answered by
mdmintz
Jan 2, 2025
As in the example here:
with SB(uc=True, test=True, ad_block=True, pls="none") as sb:
page_load_strategy
, (pls="none"
), to prevent extra waiting.
Replies: 1 comment
-
As in the example here:
with SB(uc=True, test=True, ad_block=True, pls="none") as sb:
page_load_strategy
, (pls="none"
), to prevent extra waiting.
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Answer selected by
mdmintz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment