Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.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 如何使用Selenium webdriver 3进行拖动,其中要从中拖动的基础元素是<;img>;标签_Java_Selenium_Cucumber - Fatal编程技术网

Java 如何使用Selenium webdriver 3进行拖动,其中要从中拖动的基础元素是<;img>;标签

Java 如何使用Selenium webdriver 3进行拖动,其中要从中拖动的基础元素是<;img>;标签,java,selenium,cucumber,Java,Selenium,Cucumber,我正在使用Selenium 3和Java、Cucumber和ChromeDriver。我试图从img元素中拖动,但Selenium不允许为了拖放而将焦点转移到该元素。我已经尝试了以下所有选项。请。如果有人能帮忙,请告诉我 使用键盘操作: Actions builder = new Actions(driver); builder.keyDown(Keys.CONTROL).click(someElement).click(someOtherElement). keyUp(Keys.

我正在使用Selenium 3和Java、Cucumber和ChromeDriver。我试图从img元素中拖动,但Selenium不允许为了拖放而将焦点转移到该元素。我已经尝试了以下所有选项。请。如果有人能帮忙,请告诉我

使用键盘操作:

Actions builder = new Actions(driver);
builder.keyDown(Keys.CONTROL).click(someElement).click(someOtherElement).        keyUp(Keys.CONTROL).build().perform();
使用鼠标操作:

Actions builder = new Actions(driver);
builder.clickAndHold(someElement).moveToElement(otherElement).release( otherElement).build().perform();
代码适用于Robot类:

public String dragElementFrom="//div[@class='asset-instructions col-xs-6']/div[5]/div/ul/li[1]/div/img";
public String dragElementTo="//*[@id='parity-on-page-preview']";
WebElement e=objHelp.WaitForElement(驱动程序,By.xpath(obj.dragElementFrom)); WebElement f=objHelp.WaitForElement(驱动程序,By.xpath(obj.dragElementTo))

robot类的问题是,当我运行测试时,我需要确保浏览器窗口处于焦点位置,否则robot类将无法工作


我也尝试过使用Firefox,但都是一样的。我也做了调查,但在任何地方都找不到我的答案

如果我理解正确,Selenium 3不支持HTML5拖放。他们正在努力: 有一些基于javascript的解决方案,但它们并不总是有效的

 Point coordinates1 = e.getLocation();
 Point coordinates2 = f.getLocation();
 Robot robot = new Robot();

 robot.mouseMove(coordinates1.getX()+55, coordinates1.getY()+118);
 robot.mousePress(InputEvent.BUTTON1_MASK);
 robot.mouseMove(coordinates2.getX()+200, coordinates2.getY()+200);
 robot.mouseRelease(InputEvent.BUTTON1_MASK);
 Thread.sleep(2000);