Addy
Addy

Reputation: 23

java.lang.ClassCastException: org.openqa.selenium.firefox.FirefoxDriver cannot be cast to org.openqa.selenium.interactions.HasTouchScreen

I am trying to automate a touch event using Selenium. First time doing it. This is my code:

   public void getarrowright() throws Exception {
    new AccessibilityPage(driver).getdragmeframe();
    BrowserUtils.waitForVisibility(rightarrow,30,driver);
    Actions action = new Actions(driver);
    action.moveToElement(rightarrow).click().perform();
    TouchActions tapAction = new TouchActions(driver).singleTap(rightarrow);
    tapAction.perform();
}

I am getting that as an error. This is how my driver page looks like:

case "firefox":
                caps = DesiredCapabilities.firefox();

                FirefoxOptions ffOpts = new FirefoxOptions();
                FirefoxProfile ffProfile = new FirefoxProfile();

                ffProfile.setPreference("browser.autofocus", true);
                ffProfile.setPreference("browser.tabs.remote.autostart.2", false);

                caps.setCapability(FirefoxDriver.PROFILE, ffProfile);
                caps.setCapability("marionette", true);

                // then pass them to the local WebDriver
                if (platform.equalsIgnoreCase("local")) {
                    System.setProperty("webdriver.gecko.driver", "src/main/resources/Drivers/geckodriver.exe");
                    webDriver.set(new FirefoxDriver(ffOpts.addCapabilities(caps)));
                }

                break;

Can someone please help? Thanks

Upvotes: 0

Views: 872

Answers (1)

rmunge
rmunge

Reputation: 4248

Access to touch screen capabilities is an optional feature. Driver implementations that support this feature implement the HasTouchScreen interface. According to Javadoc, ChromeDriver is so far the only implementation that implements this interface:

https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/interactions/HasTouchScreen.html

Upvotes: 1

Related Questions