How to Access Selenium Webdriver Through Splinter in Python

How to Access Selenium Webdriver Through Splinter in Python

I'm currently using Splinter to build some web automation scripts and so far so good, but I've run into an issue where I can't actually fix it using the Splinter wrapper functions. But, I believe I might have found a solution that can be fixed using the Selenium Webdriver functions even though I'm primarily using Splinter.

I believe I've done this before years ago, but no matter where I've searched (Documentation, Google, Stackoverflow) I can't seem to find anything on this, so maybe it's not a feature anymore?

Anyways basically I need to access the Selenium Webdriver functions.

From memory, I believe the code was something like:

browser = splinter.browser("firefox")
brower.visit("google.com")
browser.webdriver.find_element_by_id('loginForm') #This is calling the selenium web driver direcetly, not the Splinter find_by_id function. 

.webdriver .driver

both do not seem to work.

Does anyone know how to correctly do this? Let me know if you need any more information. Thanks for your help.

2 Answers

The selenium is exposed by driver browser attribute:

>>> from splinter import Browser
b>>> b = Browser()
>>> b.driver
<selenium.webdriver.firefox.webdriver.WebDriver (session="e607ceaa-2c63-435e-9991-432376102bf5")>
>>> 

This implementation integrates the webdriver_manager module.

Chrome Browser Example:

from splinter import Browser
from selenium import webdriver 
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.chrome.service import Service as ChromiumService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.os_manager import ChromeType

executable_path = {'executable_path': ChromeDriverManager().install()}
driver = Browser('chrome', **executable_path, headless=False)    
url = '
driver.visit(url)

Brave Browser Example:

from splinter import Browser
from selenium import webdriver 
from selenium.common.exceptions import TimeoutException
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as BraveService
from webdriver_manager.core.utils import ChromeType

executable_path = {'executable_path': ChromeDriverManager(chrome_type=ChromeType.BRAVE).install()}
option = webdriver.ChromeOptions()
option.binary_location = "/Applications/Brave  Browser"
driver = Browser('chrome', **executable_path, options=option, headless=False)    
url = '
driver.visit(url)

*** Update for Brave - executable path argument no longer needed:

option = webdriver.ChromeOptions()
option.binary_location = "/Applications/Brave  Browser"
driver = Browser('chrome', options=option, headless=False)    
url = '
driver.visit(url)

** Note: I have only tested this on Brave, the Firefox example I assume the same template. Firefox Browser Example:

from splinter import Browser
from selenium import webdriver 
from selenium.common.exceptions import TimeoutException
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.service import Service as FirefoxService

executable_path = {'executable_path': GeckoDriverManager().install()}
option = webdriver.ChromeOptions()
option.binary_location = "/Applications/"
driver = Browser('firefox', **executable_path, options=option, headless=False)    
url = '
driver.visit(url)

firefox options:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.