拖动n下降未发生 [英] Drag n Drop is NOT Happening
本文介绍了拖动n下降未发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不确定是什么问题.下面的代码应该可以正常工作.
Not sure what is the issue.. below code is supposed to work fine..
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.
}
}
我没有例外,但是Draggable 1根本不会动..我尝试了另一种方式,但是没有运气.
I am getting no exceptions but Draggable 1 wont move at all.. I tried this in another way but no luck..
Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(onlyOne)
.moveToElement(dropHere1)
.release(dropHere1)
.build();
dragAndDrop.perform();
推荐答案
这显然是已知的问题,并且有一个解决方法.授予它在Ruby中.
This is apparently a known issue and there is a workaround. Granted it is in Ruby.
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
这篇关于拖动n下降未发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文