【问题标题】:Drag and drop not working in Selenium 3.0拖放在 Selenium 3.0 中不起作用
【发布时间】:2017-05-02 19:48:00
【问题描述】:

我正在尝试下面的代码来测试 Selenium 3.0 中的拖放,发现代码不起作用,这意味着它没有显示任何错误,也没有提供预期的结果。

我在 selenium 2.53 中尝试过相同的代码,并且它正在工作。请有人检查我的代码,如果我遗漏了什么,请告诉我。

硒 3.0

浏览器:Mozilla 2.52

package dynamicXpath;

import java.util.concurrent.TimeUnit;

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.firefox.FirefoxProfile;  
import org.openqa.selenium.interactions.Action;  
import org.openqa.selenium.interactions.Actions;

public class refermeprobI {

    public static void main(String[] args) throws InterruptedException{

    System.setProperty("webdriver.gecko.driver", "D:\\Drivers\\geckodriver.exe");

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


            driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);


    driver.get("https://the-internet.herokuapp.com/drag_and_drop");

    Actions act = new Actions(driver);

    WebElement src = driver.findElement(By.xpath("//*[@id='column-a']"));
    WebElement dst = driver.findElement(By.xpath("//*[@id='column-b']"));






   act.dragAndDrop(src, dst).build().perform();

   System.out.println(driver.findElement(By.xpath("//*[@id='column-b']/header")).getText());



}

}

【问题讨论】:

  • 我在您的代码中没有看到任何错误。但我仍然不确定您的 Mozilla Firefox 版本和 geckodriver 版本。使用 Selenium 3.x,拖放对我来说效果很好。
  • 你用的是哪个版本的geckodriver?
  • 我可以看到 setEnableNativeEvents(true) 正在贬值。还能用吗?

标签: java selenium firefox selenium-webdriver


【解决方案1】:

我已经检查了您的代码。一切都很好,除非您使用 Selenium 3.0.0 然后需要设置 Desired Capabilities。我还使用 Selenium 最新 3.4 检查了您的代码。如果您使用 Selenium 3.4,则无需设置 Desired Capabilities。我用的是火狐52。 我希望这些信息能帮助您了解您遇到的问题。 谢谢

【讨论】:

    【解决方案2】:

    您也可以尝试以下操作:

     act.clickAndHold(src).moveToElement(dst).release(src).build().perform();
    

    这适用于 dragAndDrop() 不适用的某些情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多