About Selenium with Python... What is the difference between from seleniumbase import Driver
(seleniumbase) and from selenium import webdriver
(selenium, seleniumwire)?
What is the difference in "use cases"?
I see only constructor difference: seleniumbase Driver is harder to set options, then manipulaton with object are same.
from seleniumbase import Driver
driver = Driver(uc=False, headless=True, proxy=proxy, incognito=None, user_data_dir=None, extension_dir=None, binary_location=None)
from selenium import webdriver as Driver
driver = Driver.Chrome(options=options)
It sounds like you're trying to compare this:
from seleniumbase import Driver
driver = Driver()
with:
from selenium import webdriver
driver = webdriver.Chrome()
The seleniumbase driver
has more methods than the regular selenium one. The seleniumbase driver methods also have auto-selector detection, smart waiting, special assertion methods, allow truncated URLs, and support the TAG:contains("TEXT")
selector. That means you can do this:
from seleniumbase import Driver
driver = Driver()
driver.open("seleniumbase.io/simple/login")
driver.type("#username", "demo_user")
driver.type("#password", "secret_pass")
driver.click('a:contains("Sign in")')
driver.assert_exact_text("Welcome!", "h1")
driver.assert_element("img#image1")
driver.highlight("#image1")
driver.click_link("Sign out")
driver.assert_text("signed out", "#top_message")
driver.quit()
There are some other differences, such as the way options are passed. SeleniumBase options are passed as args into the Driver()
definition for the Driver()
Manager format (there are many other formats, such as SB()
, BaseCase
, etc.)
SeleniumBase also has a UC Mode option, which has special methods for letting your bots bypass CAPTCHAs that block regular Selenium bots:
from seleniumbase import Driver
driver = Driver(uc=True)
driver.uc_open_with_reconnect("https://top.gg/", 6)
driver.quit()
Here's a CAPTCHA-bypass example where clicking is required:
from seleniumbase import Driver
driver = Driver(uc=True)
driver.uc_open_with_reconnect("https://seleniumbase.io/apps/turnstile", 3)
driver.uc_switch_to_frame("iframe")
driver.uc_click("span.mark")
driver.sleep(3)
driver.quit()