Skip to content

Add an official example that uses SB() without the context manager with block #3948

@mdmintz

Description

@mdmintz

Add an official example that uses SB() without the context manager with block.


Multiple people have now asked about how to use the SB() context manager without the with block.
This is mentioned in the Python documentation, but not directly here, so I'll add an example for it.

This involves calling the built-in __enter__() and __exit__() methods to simulate the start and end of the with block.

Basic example of that:

from seleniumbase import SB

sb_context = SB()
sb = sb_context.__enter__()
sb.open("data:text/html,<h1>Test Page</h1>")
sb.highlight("h1", loops=8)
sb_context.__exit__(None, None, None)

That same example with the standard context manager with block looks like this:

from seleniumbase import SB

with SB() as sb:
    sb.open("data:text/html,<h1>Test Page</h1>")
    sb.highlight("h1", loops=8)

Metadata

Metadata

Assignees

Labels

testsThis involves test updates or new tests

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions