Search code examples
selenium-webdriversaucelabsremotewebdriver

moveToElement no longer works with Sauce Labs


I have code working locally however when I use the RemoteWebDriver with Sauce Labs account, the action seems to be ignored.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;

public class NavToURL {
    public static final String USERNAME = "uname";
    public static final String ACCESS_KEY = "uuid";
    public static final String URL = "https://" + USERNAME + ":" + ACCESS_KEY + "@ondemand.saucelabs.com:443/wd/hub";

    public static void main(String[] args) throws Exception {
        DesiredCapabilities caps = DesiredCapabilities.chrome();
        caps.setCapability("platform", "Windows 7");
        caps.setCapability("version", "51.0");
        caps.setCapability("screenResolution", "1280x768");

        WebDriver driver = new RemoteWebDriver(new URL(URL), caps);

        driver.get("http://www.webpage.com");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        driver.findElement(By.id("menu-item-177")).click();
        Thread.sleep(10000);
        WebElement emailBox = driver.findElement(By.id("email"));
        Actions actions = new Actions(driver);
        actions.moveToElement(emailBox);
        emailBox.sendKeys("[email protected]");
        driver.findElement(By.className("submit-button")).click();
        driver.quit();
    }
}

I even tried adding sleep timers just to slow down the load time for the VM on SauceLabs side. Any suggestions?


Solution

  • You forgot to add .build().perform();, e.g. actions.moveToElement(emailBox).build().perform();. I use Actions on Sauce Labs and it works fine for Chrome but it's not implemented in the marionette driver for FF and IE is giving me fits.