2017-03-17 101 views
0

我有本地代碼工作,但是當我用Sauce Labs帳戶使用RemoteWebDriver時,該操作似乎被忽略。moveToElement不再適用於醬實驗室

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(); 
    } 
} 

我甚至嘗試添加睡眠定時器只是爲了減慢SauceLabs端虛擬機的加載時間。有什麼建議麼?

回答

1

您忘記了添加.build().perform();,例如, 。我在Sauce Labs上使用Actions,它對於Chrome來說工作正常,但它沒有在FF的木偶驅動程序中實現,而IE正在給我適合。

+0

非常感謝! –

+0

如果您發現此(或任何)答案有幫助,請立即加入。如果這回答了您的問題,請將其標記爲已接受的答案。謝謝! – JeffC

相關問題