pythonseleniumsplinter

How to access a Selenium driver object in a script that relies on a Splinter browser object?


I am writing my first Python script to navigate a website, and so far I have relied exclusively on a Splinter browser object for things like .find_by_xpath() and .click(). I'm now running into some tasks where the examples I'm finding online and this site all refer to Selenium driver objects (e.g. examples referring to WebDriverWait, or to lines like "driver.execute_script("arguments[0].click();", element").

My question is this: Because I have relied on Splinter, I haven't actually explicitly defined a driver object anywhere in my code (i.e. all I wrote was browser = Browser(options here), and Splinter did the rest). Has a driver object nonetheless been created in the background when I created my browser object? If so, how can I access it? If not, do I need to rewrite my code using only Selenium, or is there a workaround to link my existing browser object with a Selenium driver object?

More generally, can you help me understand the relationship between a Splinter browser object, and a Selenium driver object?


Solution

  • Splinter provides an an abstraction layer for selenium.

    As you can see in the splinter repo in github

    When splinter creates a Browser Object is creating a Selenium Webdriver Object.

    This browser object is a top layer for the selenium webdriver object.

    I think that you can access to the driver like this:

    from splinter import Browser
    browser = Browser()
    driver = browser.driver