Skip to content

Add support methods directly into the raw driver object #2081

Closed
@mdmintz

Description

@mdmintz

Add support methods directly into the raw driver object

Currently, using the DriverContext() or Driver() formats may require using support methods for better reliability and advanced features. For example:

from seleniumbase import js_utils
from seleniumbase import page_actions
from seleniumbase import DriverContext

with DriverContext(browser="chrome", incognito=True) as driver:
    driver.get("https://seleniumbase.io/apps/calculator")
    page_actions.wait_for_element(driver, '[id="4"]').click()
    page_actions.wait_for_element(driver, '[id="2"]').click()
    page_actions.wait_for_text(driver, "42", "#output")
    js_utils.highlight_with_js(driver, "#output", loops=6)

with DriverContext() as driver:
    driver.get("https://seleniumbase.github.io/demo_page")
    js_utils.highlight_with_js(driver, "h2", loops=5)
    by_css = "css selector"
    driver.find_element(by_css, "#myTextInput").send_keys("Automation")
    driver.find_element(by_css, "#checkBox1").click()
    js_utils.highlight_with_js(driver, "img", loops=5)

If SeleniumBase extends the raw driver with support methods included, it could simplify that to just this:

from seleniumbase import DriverContext

with DriverContext(browser="chrome", incognito=True) as driver:
    driver.get("https://seleniumbase.io/apps/calculator")
    driver.click('[id="4"]')
    driver.click('[id="2"]')
    driver.assert_text("42", "#output")
    driver.highlight("#output", loops=6)

with DriverContext() as driver:
    driver.get("https://seleniumbase.github.io/demo_page")
    driver.highlight("h2")
    driver.type("#myTextInput", "Automation")
    driver.click("#checkBox1")
    driver.highlight("img", loops=6)

(That looks much cleaner and is also more reliable.)

For details on the DriverContext() and Driver() formats, see:

https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md#sb_sf_22
https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md#sb_sf_23

(The examples there will be updated once the support methods have been added in.)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions