Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

browser timeout #3383

Answered by mdmintz
IndrajeethY asked this question in Q&A
Discussion options

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?

You must be logged in to vote

As in the example here:

with SB(uc=True, test=True, ad_block=True, pls="none") as sb:
you can set the page_load_strategy, (pls="none"), to prevent extra waiting.

Replies: 1 comment

Comment options

As in the example here:

with SB(uc=True, test=True, ad_block=True, pls="none") as sb:
you can set the page_load_strategy, (pls="none"), to prevent extra waiting.
You must be logged in to vote
0 replies
Answer selected by mdmintz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /