SeleniumBase: ImportError: cannot import name 'Driver' from partially initialized module 'seleniumbase'

Hi there, just discovered seleniumbase. trying out the first example of the last video:

from seleniumbase import Driver
driver = Driver (uc=True)
try:
    driver.get("https://nowsecure.nl/#relax")
    driver.sleep(4)
    # DO MORE STUFF
finally:
    driver.quit()

getting the error:

from seleniumbase import Driver
ImportError: cannot import name 'Driver' from partially initialized module 'seleniumbase' (most likely due to a circular import) (/home/bangbuild/Documents/dev/cucumber/seleniumbase.py)

what am I missing?! thanks

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Comments: 33 (13 by maintainers)

Most upvoted comments

Man it’s amazing!!! (got it working with sudo apt install python3.10-tk) Everything is so smooth!! That’s it the test path is perfect 👍 Now I need to find how to record this window session to share it… Michael I can’t thank you enough for this amazing piece of software, truly magic ! 🙏 Have a great weekend my friend 😃

js_click(selector) lets you click on “hidden” elements. From your error message, it said ElementNotVisibleException, which is different from NoSuchElementException.

That’s PERFEEECT! So cool, thanks a lot! Still struggling with the behave files but will share with you when I’m stuck 😃

There’s a lot of text under <div class="error-summary validation-summary-errors">, so instead of trying to assert all of it with assert_exact_text(), you could do assert_text() instead for a substring match:

self.assert_text("Please check your information and try again.", "div.validation-summary-errors")

You mentioned something about having “the warning highlighted”? Do you mean --demo mode? That inserts JavaScript into the page, which can make you detected. You can also do self.activate_demo_mode() to activate Demo Mode in the middle of a test.

For the 5-second sleep at the end, just add: self.sleep(5)

I’m on it. If I’m able to pull that off and get the job I owe you big time Michael!

Amazing!! thanks so much Michael! have a great one 😃 I was getting this message: image

Like this:

from seleniumbase import BaseCase
BaseCase.main(__name__, __file__, "--uc", "-s")

class MyTestClass(BaseCase):
    def test_met_signin(self):
        if not self.undetectable:
            self.get_new_driver(undetectable=True)
        self.driver.uc_open_with_reconnect("https://www.metmuseum.org/", 2)
        self.click("a.masthead__membership")
        self.assert_exact_text("Join/Renew", "button#Member_with_Early_Views_0")
        self.click("button#Member_with_Early_Views_0")

        breakpoint()

If you run it with python, it will automatically use pytest --uc. If you run it with pytest without the --uc, then the line with get_new_driver will correct it.

Also, I didn’t encounter any CAPTCHAs on that site. Maybe they happen later, but if they don’t happen at all, then UC Mode wouldn’t be needed.

aha! of course, done!

Thanks for the explanation! man I really appreciate you taking the time 😃 Watching the selenium conf, pretty cool Michael

behave is a Python implementation of the Gherkin syntax for BDD. Cucumber is a generic implementation of the Gherkin syntax for BDD.

SeleniumBase utilizes the behave version by adding specific code around browser automation:

SeleniumBase/examples/behave_bdd

You can also generate behave scripts from existing tests: pytest --rec-behave

Or use the Recorder to generate behave scripts: sbase recorder --behave

@mdmintz found the --gui option (i’m on linux). Yes I’m watching the video right now, it’s how I discovered seleniumbase. I’m digging into the doc as well and your other videos. It’s really cool what you have done here! thank you