moveToElement不再适用于Sauce Labs

时间:2017-03-17 20:21:26

标签: selenium-webdriver saucelabs remotewebdriver

我的代码在本地运行,但是当我使用带有Sauce Labs帐户的RemoteWebDriver时,操作似乎被忽略了。

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("someone@gmail.com");
        driver.findElement(By.className("submit-button")).click();
        driver.quit();
    }
}

我甚至尝试添加睡眠定时器,以减慢SauceLabs端VM的加载时间。有什么建议吗?

1 个答案:

答案 0 :(得分:2)

您忘记添加.build().perform();,例如actions.moveToElement(emailBox).build().perform();。我在Sauce Labs上使用Actions并且它适用于Chrome,但它没有在FF和IE的牵线木偶驱动程序中实现,这让我很适合。