Selenium Webdriver -dragAndDrop无法在Firefox 32中运行

时间:2014-10-02 16:01:43

标签: java firefox selenium drag-and-drop selenium-webdriver

我正在尝试进行简单的拖放操作。不知道为什么它不会发生。 我正在使用Selenium StandAlone Server 2.43.1和firefox 32。

以下是我的代码:

@Before    
public void setUp() throws Exception {            
    driver = new FirefoxDriver();    
    baseUrl = "http://html5demos.com/drag";    
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);    
    driver.manage().window().maximize();    
  }

@Test
public void testdragAndDrop() throws Exception {    
    driver.get(baseUrl);    

    WebElement From=driver.findElement(By.xpath("/html/body/section/article/ul/li[3]/a"));    
    System.out.println(From.isDisplayed());     

    WebElement To=driver.findElement(By.xpath("/html/body/section/article/div"));    
      System.out.println(To.getTagName());     
      System.out.println(To.isEnabled());     
    Actions obj=new Actions(driver);    
    Action dragAndDrop= obj.clickAndHold(From)    
                           .moveToElement(To)    
                           .release(To)    
                           .build();    
    dragAndDrop.perform();    
    Thread.sleep(5000);    
}

我也尝试过跑步:

obj.dragAndDrop(From, To).build().perform();

仍然是相同的结果..

任何人都可以帮忙。

2 个答案:

答案 0 :(得分:1)

您好尝试为Drag-gable元素使用更独特的Xpath或Attribute,试试这个也希望它有所帮助

        Actions actions = new Actions(driver);

        actions.clickAndHold(widget).moveToElement(dragHandler).build().perform();      
        actions.release(dragHandler).perform();

答案 1 :(得分:1)

我遇到了同样的问题,它通过启用原生事件来解决:

FirefoxProfile profile = new FirefoxProfile();    
profile.setEnableNativeEvents(true);    
WebDriver driver = new FirefoxDriver(profile);