Reputation: 3426
I have had to use the Selenium Actions class to use the doubleclick method to interact with some of the elements on my page. This was working fine with the WebDriver (driver = DriverFactory.open(browserType);
) but when I convert it to my own custom WebDriver below, the double click is not performed.
When I ran in debug mode I could see that with the custom driver the doubleclick method was called, but the mouse was evaluated as null.
Does anyone know why my custom driver doesn't work with Actions?
package utilities;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class CustomWebDriver implements WebDriver, JavascriptExecutor
{
private WebDriver driver;
private boolean hasQuit = false;
public CustomWebDriver(String browserType)
{
driver = DriverFactory.open(browserType);
hasQuit = false;
}
@Override
public void get(String url)
{
driver.get(url);
}
@Override
public String getCurrentUrl()
{
return driver.getCurrentUrl();
}
@Override
public String getTitle()
{
return driver.getTitle();
}
@Override
public List<WebElement> findElements(By by)
{
return driver.findElements(by);
}
@Override
public WebElement findElement(By by)
{
return driver.findElement(by);
}
@Override
public String getPageSource()
{
return driver.getPageSource();
}
@Override
public void close()
{
driver.close();
}
@Override
public void quit()
{
driver.quit();
hasQuit = true;
}
@Override
public Set<String> getWindowHandles()
{
return driver.getWindowHandles();
}
@Override
public String getWindowHandle()
{
return driver.getWindowHandle();
}
@Override
public TargetLocator switchTo()
{
return driver.switchTo();
}
@Override
public Navigation navigate()
{
return driver.navigate();
}
@Override
public Options manage()
{
return driver.manage();
}
public boolean hasQuit()
{
return hasQuit;
}
@Override
public Object executeScript(String script, Object... args)
{
return ((JavascriptExecutor) driver).executeScript(script, args);
}
@Override
public Object executeAsyncScript(String script, Object... args)
{
return ((JavascriptExecutor) driver).executeAsyncScript(script, args);
}
}
Upvotes: 0
Views: 431
Reputation: 9058
The custom WebDriver needs to implement the Interactive interface. The Actions class calls the perform()
method of this interface in its own perform() method.
You might also need to implement the HasInputDevices interface.
You could also have extended the existing RemoteWebDriver and customized it. Spares you from duplicating methods.
Upvotes: 1