Hello, I made a whole test case by importing Driver. Now I'm realizing I need methods from the BaseCase like .switch_to_window... How to resolve? #2347
-
Any suggestions on how to fix this? I didn't write anything in a class. I usually just write a function like driver.get("url"). Then driver.click(). etc. I wrote my whole case with Driver: import seleniumbase as Driver driver.get("url") But when I got to a point where I had a window pop up, I realized that there is no driver.switch_to_window() method. Is there a workaround for this? I noticed all of the examples are in classes that call themselves? Is there any way around this? I really just want to be able to do driver.switch_to_window() Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Look for any of the tests in the SeleniumBase/examples/ folder that start with For example, here's a script that imports """Driver() test. Runs with "python". (pytest not needed)."""
from seleniumbase import Driver
driver = Driver(browser="chrome", headless=False)
try:
driver.open("seleniumbase.io/apps/calculator")
driver.click('[id="4"]')
driver.click('[id="2"]')
driver.assert_text("42", "#output")
driver.highlight("#output", loops=6)
finally:
driver.quit()
driver = Driver()
try:
driver.open("seleniumbase.github.io/demo_page")
driver.highlight("h2")
driver.type("#myTextInput", "Automation")
driver.click("#checkBox1")
driver.highlight("img", loops=6)
finally:
driver.quit() Here's a script that uses """SB Manager using UC Mode for evading bot-detection."""
from seleniumbase import SB
with SB(uc=True) as sb:
sb.driver.uc_open_with_tab("https://nowsecure.nl/#relax")
sb.sleep(1.2)
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
sb.get_new_driver(undetectable=True)
sb.driver.uc_open_with_reconnect(
"https://nowsecure.nl/#relax", reconnect_time=3
)
sb.sleep(1.2)
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
if sb.is_element_visible('iframe[src*="challenge"]'):
with sb.frame_switch('iframe[src*="challenge"]'):
sb.click("span.mark")
sb.sleep(2)
sb.activate_demo_mode()
sb.assert_text("OH YEAH, you passed!", "h1", timeout=3) |
Beta Was this translation helpful? Give feedback.
Look for any of the tests in the SeleniumBase/examples/ folder that start with
raw_
, as those are pure Python tests. (The tests start start withtest_
or end with_test.py
are tests that are meant to be run withpytest
, and those tests have that special class structure that you've noticed.) Here are thoseraw_
tests:For example, here's a script that imports
Driver
: