Skip to main content

Native Selenium WebDriver Access

Accessing the Native Selenium WebDriver

Did you know that you can use the native Selenium WebDriver with SHAFT whenever you need it?

NativeDriverAccess.java
SHAFT.GUI.WebDriver driver = new SHAFT.GUI.WebDriver();
WebDriver nativeDriver = driver.getDriver();

Example:

NativeDriverExample.java
SHAFT.GUI.WebDriver driver = new SHAFT.GUI.WebDriver();
WebDriver nativeDriver = driver.getDriver();

// Use native Selenium directly when needed
nativeDriver.findElement(By.id("lname")).sendKeys("Smith");

Wrapping an Existing WebDriver Instance

You can wrap any existing org.openqa.selenium.WebDriver instance with SHAFT capabilities. This is useful when migrating from plain Selenium to SHAFT incrementally, or when a third-party library hands you a raw driver.

WrapExistingWebDriver.java
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.shaft.driver.SHAFT;

// Start with a plain Selenium driver
WebDriver rawDriver = new ChromeDriver();
rawDriver.get("https://example.com");

// Wrap it — all SHAFT fluent actions, smart waits, and reporting now apply
SHAFT.GUI.WebDriver driver = new SHAFT.GUI.WebDriver(rawDriver);

driver.assertThat().browser().title().contains("Example").perform();
driver.element().click(By.id("ctaButton"));

driver.quit();

Why Wrap a Driver?

BenefitDescription
Fluent APIChain browser, element, and validation actions
Smart waitsAuto-wait for elements to be interactable
Allure reportingSteps and screenshots captured automatically
Incremental migrationIntroduce SHAFT into existing Selenium projects gradually
tip

After wrapping, call driver.quit() (not rawDriver.quit()) to ensure SHAFT's lifecycle hooks run correctly and the Allure report is finalised.