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

Interactive Mode / Keep Browser Open #3469

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

Hey Michael,

I'm used to running python in interactive mode so that I can select elements quickly without having to re-run my script. This lets me confirm i've selected the element I'm looking for on the webpage and run commands on the go. I've tried running my script with python -i script.py and it works but the driver closes automatically. This leads me to my next question. How do I prevent the window from closing after executing the script. In selenium, this is done by options.add_experimental_option('detach', True) - what is the equivalent in SeleniumBase?

I'm currently using the SB syntax and my code is as follows:

with SB(uc=True) as sb:
 url = "https://www.bet365.com.au/"
 sb.activate_cdp_mode(url)
 sb.cdp.click_link('Log In')

Thanks

You must be logged in to vote

Duplicate of #1814 (comment).

Use a breakpoint to keep the browser window open:

breakpoint()

Breakpoint common controls: n = next, c = continue, s = step.

When you're done with the browser window, use c and hit Enter so that SeleniumBase can safely close the browser and terminate used resources such as drivers.

Replies: 1 comment 2 replies

Comment options

Duplicate of #1814 (comment).

Use a breakpoint to keep the browser window open:

breakpoint()

Breakpoint common controls: n = next, c = continue, s = step.

When you're done with the browser window, use c and hit Enter so that SeleniumBase can safely close the browser and terminate used resources such as drivers.

You must be logged in to vote
2 replies
Comment options

Hey Michael,

Breakpoint() only pauses the script. It does not allow you to continue to use SB methods to interact with the webpage.

Comment options

Actually, it does. breakpoint() pauses script execution, giving you an interactive Python prompt via the breakpoint that keeps the browser open.

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
2 participants

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