Reputation: 59
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.
Upvotes: 1
Views: 1348
Reputation: 129
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 = 'https://google.com'
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.app/Contents/MacOS/Brave Browser"
driver = Browser('chrome', **executable_path, options=option, headless=False)
url = 'https://google.com'
driver.visit(url)
*** Update for Brave - executable path argument no longer needed:
option = webdriver.ChromeOptions()
option.binary_location = "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
driver = Browser('chrome', options=option, headless=False)
url = 'https://google.com'
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/Firefox.app/Contents/MacOS/firefox"
driver = Browser('firefox', **executable_path, options=option, headless=False)
url = 'https://google.com'
driver.visit(url)
firefox options: https://splinter-test.readthedocs.io/en/latest/drivers/firefox.html
Upvotes: 0
Reputation: 151
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")>
>>>
Upvotes: 4