Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 拖放没有发生_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java 拖放没有发生

Java 拖放没有发生,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,不确定是什么问题。。下面的代码应该可以正常工作 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.int

不确定是什么问题。。下面的代码应该可以正常工作

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.interactions.Actions;

public class jusTrails {

    public static void main(String[] args) {
        System.setProperty("webdriver.gecko.driver", "D:\\bala back up\\personel\\selenium\\Jars\\Drivers\\geckodriver.exe");
        WebDriver driver=new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);

        driver.get("http://www.seleniumeasy.com/test/drag-and-drop-demo.html");
        WebElement onlyOne=driver.findElement(By.xpath("//span[contains(text(), 'Draggable 1')]"));

        System.out.println(onlyOne.getText());
        WebElement dropHere1=driver.findElement(By.xpath("//*[@id='mydropzone']"));
        Actions act=new Actions(driver);
        act.dragAndDrop(onlyOne, dropHere1).build().perform(); //This should work fine.. BUT.

    }

}
我没有得到任何例外,但可拖动的1根本不会移动。。我用另一种方法试过,但没有成功

Actions builder = new Actions(driver);

Action dragAndDrop = builder.clickAndHold(onlyOne)
    .moveToElement(dropHere1)
    .release(dropHere1)
    .build();

dragAndDrop.perform();

这显然是一个已知的,有一个。当然是红宝石的

def drag_and_drop(source,target)

    js_filepath=File.dirname(__FILE__)+"/drag_and_drop_helper.js"
    js_file= File.new(js_filepath,"r")
    java_script=""

    while (line=js_file.gets)
      java_script+=line
    end

    js_file.close

    @driver.execute_script(java_script+"$('#{source}').simulateDragDrop({ 
dropTarget: '#{target}'});")

    rescue Exception => e
      puts "ERROR :" + e.to_s

  end

请与您的XPathNoXPath问题联系。。我确信事实上我也尝试过类似的步骤。。但不确定上面的错误是什么,可能是3.4.0版(chrome和firefox版)中也没有解决的问题。哇,好的,谢谢你的info@MorficIts在java中非常不幸,没有解决办法。谢谢你的意见@TitusLucretius